如何将数据库表列绑定到下拉列表? [英] how to bind database table columns to the dropdownlist?
本文介绍了如何将数据库表列绑定到下拉列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hai先生,
如何将数据库表列绑定到下拉列表?
hai sir,
how to bind database table columns to the dropdownlist?
推荐答案
您可以尝试使用此代码绑定Datatable列to DropDownlist
you can try this code for binding Datatable column to DropDownlist
//str is Connection String
SqlConnection con = new SqlConnection(str);
string com = "Select * from tableName";
SqlDataAdapter adpt = new SqlDataAdapter(com, con);
DataTable dt = new DataTable();
adpt.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "ID";
DropDownList1.DataBind();
这篇关于如何将数据库表列绑定到下拉列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文