我已经尝试了这个,但它不起作用,给出了null值:请告诉我这段代码中需要更改的内容。
protected void Button1_Click(object sender, EventArgs e)
{
GridViewRow row;
row = dgData.Rows[0];
DropDownList ddl= (DropDownList)(row.Cells[1].FindControl("ddlCol1"));
}
答案 0 :(得分:0)
使用
DropDownList ddl =(DropDownList)(row.FindControl(“ddlCol1”));
并尝试让我知道
答案 1 :(得分:0)
在点击事件
上尝试此代码foreach (GridViewRow row in GridView1.Rows)
{
//Finding Dropdown control
DropDownList ddl1 = row.FindControl("ddlTest") as DropDownList;
if (ddl1 != null)
{
// your code here
}
}
答案 2 :(得分:0)
@creby我看到了你的代码。
您在行数据绑定事件期间在网格视图中添加下拉列表确定..但是现在当您单击按钮时,所有下拉列表都将消失,这就是您无法下拉的原因。
使用网格视图的项模板,然后在行数据绑定事件中绑定下拉列表。