62,041
社区成员
发帖
与我相关
我的任务
分享
for (int i = 0; i < GV.Rows.Count; i++)//GV是你的GridView
{
DropDownList Dp=(DropDownList)GV.Rows[i].FindControl("你的DropDownList的ID");
Dp.SelectedValue=DataTable1.Rows[i]["su_ID"].ToString();//"想要显示的su_ID",这里以DataTable数据源为例;
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{
su_ID=Int32.Parse(e.Row.Cells[0].Text);
express="su_ID="+su_ID;
DropDownList ddl=(DropDownList)e.Row.FindControl("DropDownList1");
DataRow[] rows=ds.Tables[0].Select(express);
foreach(DataRow row in rows)
{
DataRow newRow=myTable.NewRow();
newRow["ProductID"]=row["ProductID"];
newRow["ProductName"]=row["ProductName"];
myTable.Rows.Add(newRow);
}
ddl.DataSource=myTable;
ddl.DataTextField="ProductName";
ddl.DataValueField="ProductID";
ddl.DataBind();
}
}