C# ASP.NET编辑GridView行
编辑时,同一行中有3个下拉列表 当1个dropdownlist有一个选择时,其他2个应该转到索引0(空索引) 我的代码示例:C# ASP.NET编辑GridView行,c#,asp.net,linq,C#,Asp.net,Linq,编辑时,同一行中有3个下拉列表 当1个dropdownlist有一个选择时,其他2个应该转到索引0(空索引) 我的代码示例: <asp:TemplateField HeaderText="Project" SortExpression="Project"> <ItemTemplate> <%#Eval("Project") %>
<asp:TemplateField HeaderText="Project" SortExpression="Project">
<ItemTemplate>
<%#Eval("Project") %>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ProjectDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ProjectDropDownList_Changed" AppendDataBoundItems="true"
DataSourceID="ProjectDataSource" DataTextField="navn" DataValueField="navn">
<asp:ListItem>-- choose one --</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
我在尝试获取同一行中的其他控件时得到一个空指针。。。如何修复此问题?我不确定您要查找的是SelectedIndex。是否有您应该使用的EditItemIndex?Nullpointer用于哪个对象?DropDownList的Nullpointer用于我试图到达UpdateEvent/EditingEvent之外的位置。这已经足够简单了!如下所示:
DropDownList项目=(DropDownList)GridView1.Rows[GridView1.EditIndex].FindControl(“ProjectDropDownList”)代码>
protected void ProjektDropDownList_SelectionChanged(object sender, EventArgs e)
{
DropDownList project = (DropDownList) GridView1.Rows[GridView1.SelectedIndex].FindControl("ProjectDropDownList");
DropDownList kunde = (DropDownList)GridView1.Rows[GridView1.SelectedIndex].FindControl("KundeDropDownList");
DropDownList øvrige = (DropDownList)GridView1.Rows[GridView1.SelectedIndex].FindControl("ØvrigeDropDownList");
if(project.SelectedIndex >= 0 && kunde != null && øvrige != null) {
kunde.SelectedIndex = 0;
øvrige.SelectedIndex = 0;
}
}