小编NJo*_*hns的帖子

gridview中的c#dropdownlist selectedindexchanged设置第二个下拉列表的selectedindex

我有一个gridview,其中有两个从db填充的下拉列表.一个是描述性名称,另一个是缩写名称.我需要完成以下任务:

当我在DDL1中选择一个项目时,我需要更改所选的DDL2索引以匹配,反之亦然.

我在这里搜索过,发现了以下内容:

protected void ddlAddLabTest_SelectedIndexChanged(object sender, EventArgs e)
{
   DropDownList ddlLabTest = (DropDownList)sender;
   GridViewRow row = (GridViewRow)ddlLabTest.NamingContainer;
   DropDownList ddlAddLabTestShortName = (DropDownList)row.FindControl("ddlAddShortname");

   ddlAddLabTestShortName.SelectedIndex = intSelectedIndex;
}
Run Code Online (Sandbox Code Playgroud)

只有当它到达"行"的分配时,我才会收到以下内容:

Unable to cast object of type 'System.Web.UI.WebControls.DataGridItem' to type 'System.Web.UI.WebControls.GridViewRow'.
Run Code Online (Sandbox Code Playgroud)

我试过找一个有效的例子,但我做不到.任何帮助是极大的赞赏!

c# gridview selectedindexchanged drop-down-menu

2
推荐指数
1
解决办法
2万
查看次数