如何给datagrid中的下拉列表添加数据

来源:百度知道 编辑:UC知道 时间:2024/06/17 23:55:32
web程序中,如何给datagrid中的dropdownlist绑定数据库的数据。
希望给出思路和关键代码。
谢谢!

先指定数据源,然后读取数据库表中的某一列,再绑定。给你个我最近写的参考一下。
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
ds = dc.GetDataSet("select dbo.MstHierarchyBelong1.Belong1Code,dbo.MstHierarchyBelong1.Belong1Name from dbo.MstHierarchyBelong1 where dbo.MstHierarchyBelong1.DeleteKBN <> 1 and dbo.MstHierarchyBelong1.Company_code = 10005");(这里添加你自己的查询语句)
if( ds == null)
{
Page.RegisterStartupScript("","<script> alert('データ抽出が失败しました。')</script>");
return;
}

DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataValueField = "Belong1Code";
DropDownList1.DataTextField = "Belong1Name";
DropDownList1.DataBind();

DropDownList1.Items.Insert(0,"ご选択ください");

string str_kk = "";
str_kk = ”你的数据库查询语句”
ds = dc.GetDataSet(str_kk);
DataGrid1.DataSource = ds.Table