Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ASP.NET编辑GridView行_C#_Asp.net_Linq - Fatal编程技术网

C# ASP.NET编辑GridView行

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") %>

编辑时,同一行中有3个下拉列表

当1个dropdownlist有一个选择时,其他2个应该转到索引0(空索引)

我的代码示例:

                <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;
            }

        }