如何在数据库的dropdowlist中填充数据? [英] how to populate data in dropdowlist from database?
本文介绍了如何在数据库的dropdowlist中填充数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个表
1. state(state_id,state_name) state_id PK,身份规范
2.city(city_id,city_name .state_id)city_id
i have 3 tables
1. state(state_id,state_name) state_id PK,Identity specification
2.city (city_id,city_name.state_id) city_id
推荐答案
您的问题不明确。但根据我的理解,你想将数据库值绑定到DropDownList ..?对... ...
用于从DataBase获取信息,然后将该信息存储在DataSet中并将该DataSet绑定到DropDownList 。
Ex:
Your Question is not clear. But as per my understanding you want to bind the database values to DropDownList..? right...?
for that fetch the information from DataBase , and then store that information in DataSet and bind that DataSet to DropDownList.
Ex:
DataSet ds=// fetch Data from DB;
ddl.DataSource=ds;
ddl.DataTextField="Name";
ddl.DataValueField="Id";
ddl.DataBind();
如果您想了解更多相关信息,可以在谷歌搜索。
在Google中,您可以获得有关此主题的更多结果...
if you want more information regarding this you can search in google.
In google you get more results regarding this topic...
// This is I've done for Document Type, based on it you can do it for your own query.
EditDocTypeDropDown.DataSource = bc.FillDocTypeDropDown(); // Fetch value for DropDown from Database
EditDocTypeDropDown.DataValueField = "type_id";
EditDocTypeDropDown.DataTextField = "type";
EditDocTypeDropDown.DataBind();
SqlDataSource sqlDS = new SqlDataSource();
sqlDS.ConnectionString = ConfigurationManager.ConnectionStrings[0].ToString();
sqlDS.SelectCommand = "select state_id,state_name from State";
form1.Controls.Add(sqlDS);
DropDownList ddl = new DropDownList();
ddl.ID = "dddlState";
ddl.DataSource = sqlDS;
ddl.DataTextField = "state_name";
ddl.DataValueField = "state_id";
form1.Controls.Add(ddl);
在dd1的更改索引事件中你可以输入代码
on the Change Index event of dd1 you can put the code
SqlDataSource sqlDS = new SqlDataSource();
sqlDS.ConnectionString = ConfigurationManager.ConnectionStrings[0].ToString();
sqlDS.SelectCommand = "select city_id,city_name from city where state_id=''+dddlState.Value.Text()+"''";
form1.Controls.Add(sqlDS);
DropDownList dd2 = new DropDownList();
dd2.ID = "dddlCity";
dd2.DataSource = sqlDS;
dd2.DataTextField = "City_name";
dd2.DataValueField = "city_id";
form1.Controls.Add(dd2);
这篇关于如何在数据库的dropdowlist中填充数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文