本文介绍了将数据绑定到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两个下拉列表
1-ddlcity
2-ddlBranch

我在SQL数据库中从tblCity绑定了ddlcity

代码在这里:

Hi,

I have two dropdownlist
1-ddlcity
2-ddlBranch

I bind the ddlcity from tblCity in sql database

the code is here:

Protected Sub Page_DataBinding(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.DataBinding
        Dim conn As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("schoolz").ConnectionString)
        conn.Open()
        Dim cmd As New SqlCommand("select strName from tblCity", conn)
        Dim dr As SqlDataReader
        dr = cmd.ExecuteReader()
        ddlCity.DataSource = dr
        ddlCity.DataTextField = "strName"
        ddlCity.DataBind()
        dr.Close()
        conn.Close()
    End Sub



我希望当我从ddlcity中选择城市时,所有分支将显示在第二个下拉ddlBranch中.

为此,我编写了存储过程



I want that when I select the city from ddlcity, then all the branch will display in the second dropdown ddlBranch.

For this I write the stored procedure

create proc spEditReport
@intReturnAdd int=0 output
as
begin
declare @add int
select strName from tblBranch where intAddressID=@intReturnAdd

select @add= tblAddress.intAddressID
from tblAddress  join tblCity
on tblAddress.intAddressID=tblCity.intCityID
if @@error <> 0
    begin
        rollback transaction
        return @intReturnAdd
    end
    commit transaction
    set @intReturnAdd = @add
    return @intReturnAdd
end




选择城市时,有人可以告诉我如何编码以显示分支吗?


请帮帮我.
谢谢和问候
subiya




Can anybody tell me how to code to display the branches when I select the city?


please help me out.
thanks and regard
subiya

推荐答案


 Dim sd As New SqlDataAdapter("select cityID from tableCity where cityName=''" + cmb1.SelectedText.ToString() + "''",connection)
        Dim dt As New DataTable
        sd.Fill(dt)
        If dt.Rows.Count > 0 Then
conn.Open()
        Dim cmd1 As New SqlCommand("select BranchNames from tableBranch where cityID=''"+dt.Rows (0).Item (0).ToString ()+"''", conn)
        Dim dr1 As SqlDataReader
        dr1 = cmd.ExecuteReader()
      ddlBranch.DataSource = dr1
        ddlBranch.DataTextField = "BranchName"
        ddlBranch.DataBind()
        dr1.Close()
        conn.Close()


根据您的需要实施它.我以Field为例,所以请检查并尝试


Implement this as Per Your need.I have taken Field Just For Example.So check it and Try


这篇关于将数据绑定到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 21:48
查看更多