0

在 chkSubModuleView_CheckedChanged() 事件上,我想获取 chkModule 的 id。请告诉我如何在服务器端单击子复选框时获取父复选框的 id 或引用。如何区分不同的模块。

enter code here

<asp:ListView ID="lvModule" runat="server">
                <LayoutTemplate>
                    <table width="600px" border="0" cellpadding="0" cellspacing="0"     
class="ListViewtable">
                        <tr>
                            <th style="width: 10%;">
                                Modules
                            </th>
                        </tr>
                        <asp:PlaceHolder ID="itemPlaceholder" runat="server"> 
</asp:PlaceHolder>
                    </table>
                </LayoutTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <asp:CheckBox ID="chkModule" runat="server"   
CausesValidation="false" AutoPostBack="true"
                                OnCheckedChanged="chkModule_CheckedChanged" > 
</asp:CheckBox><asp:HiddenField ID="hfEntityName"
                                    Value='<%# Eval("EntityName") %>' runat="server" />
                            <%# Eval("Title")%>
                            <asp:HiddenField ID="hfID" Value='<%# Eval("ID") %>'   
runat="server" />
                            <asp:Label ID="label" runat="server"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" style="padding-left: 20px;">
                            <asp:ListView ID="lvSubModule" runat="server">
                                <LayoutTemplate>
                                    <table width="100%" cellspacing="0" border="0"   
class="ListViewtableLayer2">
                                        <tr>
                                            <th style="width: 20%;">
                                                Sub Module
                                            </th>
                                            <th style="width: 20%;">
                                                <asp:CheckBox ID="chkSubModuleView"  
Checked="true" runat="server" AutoPostBack="true"

OnCheckedChanged="chkSubModuleView_CheckedChanged" />
                                                View
                                            </th>

                                        </tr>
                                        <asp:PlaceHolder ID="itemPlaceholder"   
runat="server"></asp:PlaceHolder>
                                    </table>
                                </LayoutTemplate>
                                <ItemTemplate>
                                    <tr>
                                        <td>
                                            <%# Eval("Title")%>
                                            <asp:HiddenField ID="hfMenuID" Value='<%#  
Eval("MenuID") %>' runat="server" />
                                            <asp:HiddenField ID="hfName" Value='<%#   
Eval("HeaderID") %>' runat="server" />
                                        </td>
                                        <td>
                                            <asp:CheckBox ID="chkRead" runat="server"  
AutoPostBack="true" Checked="true" CausesValidation="false"

OnCheckedChanged="chkRead_CheckedChanged"></asp:CheckBox>
                                        </td>

                                    </tr>
                                </ItemTemplate>
                            </asp:ListView>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:ListView>
4

1 回答 1

0

将您的复选框属性更改为

<asp:CheckBox ID="chkSubModuleView"  
Checked="true" runat="server" AutoPostBack="true"  Key='<%# Eval("ID")%>'
OnCheckedChanged="chkSubModuleView_CheckedChanged" />

在你的 .cs

protected void chkSubModuleView_CheckedChanged(object sender, EventArgs e)  
{  
CheckBox chk = (CheckBox)sender;
string yourID = chk.Attributes["Key"].ToString();
} 
于 2013-06-22T07:21:04.947 回答