ASP.NET Editing a GridView row

本文关键字:GridView row Editing NET ASP | 更新日期: 2023-09-27 17:57:35

当我编辑时,有3个Dropdownlists在同一行。

当1个下拉列表有一个选择时,其他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>

我的SelectionChanged偶数处理程序:

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

在尝试获取同一行中的其他控件时,我得到了一个null指针。。。我该如何解决这个问题?

ASP.NET Editing a GridView row

我不确定您要找的是SelectedIndex。难道没有应该使用的EditItemIndex吗?