与sqlDb的Dropdownlist连接 [英] Dropdownlist connection to sqlDb
问题描述
第1部分)我想将DropDownlist框控件连接到SqlDb ..tried下面的代码但没有工作
' cmd.Connection = cn
'cmd.CommandText =从Acct_Sum中选择*
'dr = cmd.ExecuteReader()
'DPList .DataSource = ds.Tables(Acct_Sum)
'DPList.DataValueField =coBor_Name
'DPList.DataTextField =coBor_Name
'cn.Close()
第2部分)另外,我想根据项目的选择更改2个texbox的内容下拉列表。
我发现它完成了第一部分使用:选择DropDownlist的数据源选项,
但不能同时做两件事。第2部分
Plz帮助thnx ...
Hi,
part 1) I want to connect DropDownlist box control to SqlDb..tried below code but not working
'cmd.Connection = cn
'cmd.CommandText = "Select * from Acct_Sum"
'dr = cmd.ExecuteReader()
'DPList.DataSource = ds.Tables("Acct_Sum")
'DPList.DataValueField = "coBor_Name"
'DPList.DataTextField = "coBor_Name"
'cn.Close()
part 2)Also I want to change the content of 2 texboxes based on selection of item from dropdownlist.
I found it done the first part using : Choose data source option of DropDownlist,
but not able to do both.i.e part 2
Plz help thnx...
推荐答案
试试这个... :)
Try this...:)
private void FillDropDownList()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
SqlCommand cmd = new SqlCommand("Select * from Acct_Sum", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataTextField = ds.Tables[0].Columns["coBor_Name"].ToString();
DropDownList1.DataValueField = ds.Tables[0].Columns["coBor_Name"].ToString();
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataBind();
}
这篇关于与sqlDb的Dropdownlist连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!