本文介绍了绑定下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void BindDropDown()
{
using (SqlConnection con = new SqlConnection(@"Data Source=maj-056\sqlexpress;Initial Catalog=Sample;Integrated Security=True;Pooling=False"))
{
SqlCommand cmd = new SqlCommand("sp_select", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataTextField = "";
DropDownList1.DataValueField = "";
DropDownList1.DataBind();
DropDownList2.DataSource = ds.Tables[1];
DropDownList2.DataTextField = "";
DropDownList2.DataValueField = "";
DropDownList2.DataBind();
DropDownList3.DataSource = ds.Tables[2];
DropDownList3.DataTextField = "";
DropDownList3.DataValueField = "";
DropDownList3.DataBind();
}
}
}
create proc sp_select
as
begin
select * from Table1
end
begin
select * from Table2
end
begin
select * from Table3
end
推荐答案
这篇关于绑定下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!