无法在嵌套的GridView中读取RadioButton

时间:2017-06-02 01:55:31

标签: c# gridview radiobuttonlist

我有一个嵌套的GridView到5个级别,我很难访问在第二级GridView中选择哪个RadioButtonList。 (第一级被命名为gvSecondLevel,所以请不要混淆)。我现在必须从gvThirdLevel访问(实际上是第二级网格,你会在代码中看到)。我不确定问题是ASPX代码还是c#代码。我已经尝试将rbThirdLevel放在TemplateField中,没有它。但无论如何我无法访问它。这是aspx代码:

<table align="left">
 <tr>
 <td colspan="2">
    <asp:GridView ID="gvSecondLevel" runat="server" AutoGenerateColumns="False" Width="800px"
    ShowFooter="True" BorderStyle="none" DataKeyNames="CallCategory_ID" OnRowDataBound="gvSecondLevel_OnRowDataBound"
    OnRowCommand="gvSecondLevel_RowCommand" OnRowDeleting="gv_RowDeleting" AllowPaging="true"
    PageSize="10" OnPageIndexChanging="gvSecondLevel_PageIndexChanging" OnRowCreated="gvSecondLevel_RowCreated" >
    <Columns>
        <asp:TemplateField HeaderText="ID" HeaderStyle-Width="20px">
            <ItemTemplate>
                <asp:Label ID="lblBusinessID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"CallCategory_ID") %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle Width="20px" />
        </asp:TemplateField>
        <asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 2nd" />
        <asp:TemplateField HeaderText="" ItemStyle-Width="20px">
            <ItemTemplate>
                <asp:LinkButton ID="lbtnDeleteSecondLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
                    CommandName="Delete" runat="server"></asp:LinkButton>
            </ItemTemplate>
            <ItemStyle Width="20px" />
        </asp:TemplateField>
        <asp:TemplateField HeaderStyle-BorderStyle="None" FooterStyle-BorderStyle="None"
            ItemStyle-BorderStyle="None">
            <ItemTemplate>
                <tr>
                    <td id="td_div<%# Eval("CallCategory_ID") %>" colspan="100%" style="border: none;">
                        <div id="div<%# Eval("CallCategory_ID") %>" style="overflow: auto; display: none;
                            position: relative; left: 15px; overflow: auto">
                            <asp:GridView ID="gvThirdLevel" runat="server" Width="95%" AutoGenerateColumns="false"
                                ShowFooter="true" BorderStyle="none" DataKeyNames="CallCategory_ID" OnRowDataBound="gvThirdLevel_OnRowDataBound"
                                OnRowCommand="gvThirdLevel_RowCommand" OnRowDeleting="gv_RowDeleting">
                                <Columns>
                                     <asp:TemplateField HeaderText="ID" Visible="true" HeaderStyle-Width="20px">
                                        <ItemTemplate>
                                            <asp:Label ID="lblCallCategoryID" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CallCategory_ID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 3rd" />
                                    <asp:TemplateField HeaderText="" ItemStyle-Width="20px">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="lbtnDeleteThirdLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
                                                CommandName="Delete" runat="server">Deactivate</asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-BorderStyle="None" FooterStyle-BorderStyle="None"
                                        ItemStyle-BorderStyle="None">
                                        <ItemTemplate>
                                            <tr>
                                                <td id="td_div1<%# Eval("CallCategory_ID") %>" colspan="100%" style="border: none;">
                                                    <div id="div1<%# Eval("CallCategory_ID") %>" style="overflow: auto; display: none;
                                                        position: relative; left: 15px; overflow: auto">
                                                        <asp:GridView ID="gvFourthLevel" runat="server" Width="95%" AutoGenerateColumns="false"
                                                            BorderStyle="none" ShowFooter="true" OnRowDataBound="gvFourthLevel_OnRowDataBound"
                                                            OnRowCommand="gvFourthLevel_RowCommand" OnRowDeleting="gv_RowDeleting" DataKeyNames="CallCategory_ID">
                                                            <Columns>
                                                                 <asp:TemplateField HeaderText="ID" HeaderStyle-Width="20px">
                                                                    <ItemTemplate>
                                                                        <asp:Label ID="lblCallCategoryID_Fourth" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CallCategory_ID") %>'></asp:Label>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 4th" />
                                                                <asp:TemplateField HeaderText="" ItemStyle-Width="20px">
                                                                    <ItemTemplate>
                                                                        <asp:LinkButton ID="lbtnDeleteFourthLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
                                                                            CommandName="Delete" runat="server">Deactivate</asp:LinkButton>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                                <asp:TemplateField HeaderStyle-BorderStyle="None" FooterStyle-BorderStyle="None"
                                                                    ItemStyle-BorderStyle="None">
                                                                    <ItemTemplate>
                                                                        <tr>
                                                                            <td id="td_div2<%# Eval("CallCategory_ID") %>" colspan="100%" style="border: none;">
                                                                                <div id="div2<%# Eval("CallCategory_ID") %>" style="overflow: auto; display: none;
                                                                                    position: relative; left: 15px; overflow: auto">
                                                                                    <asp:GridView ID="gvFifthLevel" runat="server" Width="95%" AutoGenerateColumns="false"
                                                                                        BorderStyle="none" ShowFooter="true" OnRowDataBound="gvFifthLevel_OnRowDataBound"
                                                                                        OnRowCommand="gvFifthLevel_RowCommand" OnRowDeleting="gv_RowDeleting" DataKeyNames="CallCategory_ID">
                                                                                        <Columns>
                                                                                           <asp:TemplateField HeaderText="ID" HeaderStyle-Width="20px">
                                                                                                <ItemTemplate>
                                                                                                    <asp:Label ID="lblCallCategoryID_Fifth" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "CallCategory_ID") %>'></asp:Label>
                                                                                                </ItemTemplate>
                                                                                            </asp:TemplateField>
                                                                                            <asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 5th" />
                                                                                            <asp:TemplateField HeaderText="" ItemStyle-Width="20px">
                                                                                                <ItemTemplate>
                                                                                                    <asp:LinkButton ID="lbtnDeleteFifthLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
                                                                                                        CommandName="Delete" runat="server">Deactivate</asp:LinkButton>
                                                                                                </ItemTemplate>
                                                                                            </asp:TemplateField>
                                                                                            <asp:TemplateField HeaderStyle-BorderStyle="None" FooterStyle-BorderStyle="None"
                                                                                                ItemStyle-BorderStyle="None">
                                                                                                <ItemTemplate>
                                                                                                    <tr>
                                                                                                        <td id="td_div3<%# Eval("CallCategory_ID") %>" colspan="100%" style="border: none;">
                                                                                                            <div id="div3<%# Eval("CallCategory_ID") %>" style="overflow: auto; display: none;
                                                                                                                position: relative; left: 15px; overflow: auto">
                                                                                                                <asp:GridView ID="gvSixthLevel" runat="server" Width="95%" AutoGenerateColumns="false"
                                                                                                                    BorderStyle="none" ShowFooter="true" OnRowDataBound="gvSixthLevel_OnRowDataBound"
                                                                                                                    OnRowCommand="gvSixthLevel_RowCommand" OnRowDeleting="gv_RowDeleting">
                                                                                                                    <Columns>
                                                                                                                        <asp:BoundField DataField="CallCategory_ID" HeaderText="ID" HeaderStyle-Width="20px" />
                                                                                                                        <asp:BoundField DataField="CallCategory_Name" HeaderText="Call Category Name 6th" />
                                                                                                                        <asp:TemplateField HeaderText="" ItemStyle-Width="20px">
                                                                                                                            <ItemTemplate>
                                                                                                                                <asp:LinkButton ID="lbtnDeleteSixthLevel" CommandArgument='<%# Eval("CallCategory_ID") %>'
                                                                                                                                    CommandName="Delete" runat="server">Deactivate</asp:LinkButton>
                                                                                                                            </ItemTemplate>
                                                                                                                        </asp:TemplateField>
                                                                                                                    </Columns>
                                                                                                                </asp:GridView>
                                                                                                               <asp:RadioButtonList ID="rbSixthLevel" runat="server" 
                                                                                                                onselectedindexchanged="rbSixthLevel_SelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="True">
                                                                                                                <asp:ListItem Selected="True">Active</asp:ListItem>
                                                                                                                <asp:ListItem>Inactive</asp:ListItem>
                                                                                                                </asp:RadioButtonList>
                                                                                                              </div>
                                                                                                        </td>
                                                                                                    </tr>
                                                                                                </ItemTemplate>
                                                                                            </asp:TemplateField>
                                                                                        </Columns>
                                                                                      </asp:GridView>
                                                                                    <asp:RadioButtonList ID="rbFifthLevel" runat="server" onselectedindexchanged="rbFifthLevel_SelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="True">
                                                                                    <asp:ListItem Selected="True">Active</asp:ListItem>
                                                                                        <asp:ListItem>Inactive</asp:ListItem>
                                                                                </asp:RadioButtonList>
                                                                             </td>
                                                                        </tr>
                                                                    </ItemTemplate>
                                                                </asp:TemplateField>
                                                            </Columns>
                                                        </asp:GridView>
                                                        <asp:RadioButtonList ID="rbFourthLevel" runat="server" onselectedindexchanged="rbFourthLevel_SelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="True">
                                                            <asp:ListItem Selected="True">Active</asp:ListItem>
                                                            <asp:ListItem>Inactive</asp:ListItem>
                                                        </asp:RadioButtonList>
                                                    </div>
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                            <asp:TemplateField>
                            <ItemTemplate>
                              <asp:RadioButtonList ID="rbThirdLevel" runat="server" onselectedindexchanged="rbThirdLevel_SelectedIndexChanged" RepeatDirection="Horizontal" AutoPostBack="True">
                                <asp:ListItem Selected="True">Active</asp:ListItem>
                                <asp:ListItem>Inactive</asp:ListItem>
                                </asp:RadioButtonList>
                             </ItemTemplate>
                            </asp:TemplateField>
                            </div>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>
<asp:RadioButtonList ID="rbSecondLevel" runat="server" onselectedindexchanged="rbSecondLevel_SelectedIndexChanged" 

RepeatDirection="Horizontal" AutoPostBack="True">
        <asp:ListItem Selected="True">Active</asp:ListItem>
        <asp:ListItem>Inactive</asp:ListItem>
    </asp:RadioButtonList>
 </td>
</tr>
</table>

C#代码只是返回&#34;活跃&#34;即使我选择&#34; Inactive&#34;。请指导访问rbThirdLevel

的正确方法
        protected void rbThirdLevel_SelectedIndexChanged(object sender, EventArgs e)
    {

        foreach (GridViewRow row in gvSecondLevel.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                GridView gvThirdLevel = (GridView)row.FindControl("gvThirdLevel");
                if (gvThirdLevel != null)
                {
                    RadioButtonList rbThirdLevel = gvSecondLevel.Rows[row.RowIndex].FindControl("rbThirdLevel") as RadioButtonList;
                    string radiovalue = (gvSecondLevel.Rows[row.RowIndex].FindControl("rbThirdLevel") as RadioButtonList).SelectedItem.Value;
                    if (rbThirdLevel.SelectedValue == "Inactive")
                    {
                        //code to display Deactivated rows
                    }
                    if (rbThirdLevel.SelectedValue == "Active")
                    {
                        //code to display Activated rows
                    }

               }

            }
        }

}

0 个答案:

没有答案