如何从数据库中获取记录到C#coading中的下拉列表 [英] How to fetch record from database to dropdown in C# coading
问题描述
我根据一个下拉列表下载了2个下拉列表填充数据。但取得记录第二次下拉没有从数据库获取记录
我尝试过:
用于从数据库中获取记录我使用此代码:
ddldropdownname.SelectedIndex = ddldropdownname.Items.IndexOf(ddldropdownname.Items.FindByText(sdr [value]。ToString() ));
i have taken 2 dropdowns according to one dropdown another dropdown filling data. but while fetching record 2nd dropdown not getting record from database
What I have tried:
for fetching record from database i have use this code:
ddldropdownname.SelectedIndex = ddldropdownname.Items.IndexOf(ddldropdownname.Items.FindByText(sdr["value"].ToString()));
推荐答案
你想要级联下拉。
使用Sangani编程:使用Web服务级联下拉列表 [ ^ ]
或者你想要没有级联
第一个下拉列表生成事件选择索引更改并设置autopostback =true如
you have want like cascading drop down.
Programming With Sangani: Cascading Dropdownlist using webservices[^]
or you want with out cascading
1st dropdown generate event selected index change and set autopostback ="true" like
<asp:dropdownlist id="dropcategory" runat="server" cssclass="styled span12" AutoPostBack="True" onprerender="dropcategory_PreRender" onselectedindexchanged="dropcategory_SelectedIndexChanged"> </asp:dropdownlist>
和Code Behind Selected Change事件编写如下代码。根据您的要求进行更改
and Code Behind Selected Change event write below code. changes as per your requirment
if (dropcategory.SelectedIndex != 0)
{
DataTable objdt = new DataTable();
objdt = odal.selectbyquerydt("Select * from Sub_category_Master where cid ='" + Convert.ToInt32(dropcategory.SelectedValue) + "'");
dropsubcategory.DataSource = objdt;
dropsubcategory.DataValueField = "id";
dropsubcategory.DataTextField = "Subcategory";
dropsubcategory.DataBind();
dropsubcategory.Items.Insert(0, "----Select----");
}
这篇关于如何从数据库中获取记录到C#coading中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!