ASP.NET编辑GridView行

时间:2011-05-22 11:50:01

标签: c# asp.net linq

我编辑时在同一行中有3个下拉列表。

当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>

My SelectionChanged even handler:

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

        }

我在尝试获取同一行中的其他控件时得到一个nullpointer ...我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我不确定它是您正在寻找的SelectedIndex。是不是你应该使用EditItemIndex?