protected void Button3_Click(object sender, EventArgs e)
    {
        string id="";
        for (int i = 0; i < dla.Items.Count; i++)
        {
            DataList dl = (DataList)dla.Items[i].FindControl("dl_min");
            for (int j = 0; j < dl.Items.Count; j++)
            {
                HtmlInputCheckBox cb = (HtmlInputCheckBox)dl.Items[j].FindControl("CheckRow");
                if (cb.Checked == true)
                {
                    string strid;
                    id = cb.Value.ToString();
                    strid = id + ",";
                    Response.Write(strid);
                }
            }
        }    }
注:dla和dl_min是外和内嵌套。CheckRow是内嵌套的HtmlInputCheckBox,我测试过,去掉if(cb.Checked==true)语句时,当点击button3,会把所有 CheckRow的value读到页面上,可是当if(cb.Checked==true)时,单击CheckBox就不会显示任何数据。就是说:在两层嵌套中,当单击其中一个checkbox时,取不到对应的value!

解决方案 »

  1.   

    两个嵌套:
    <asp:DataList ID="dla" runat="server" CellPadding="5" OnItemDataBound="dl_oidb" RepeatColumns="2" >
                <ItemTemplate>  
                        <table border="0" cellpadding="0" cellspacing="0" width="400" height="70">
                            <tr>
                                <td style="border-right: lightblue 1px solid; border-top: lightblue 1px solid;
                                    border-left: lightblue 1px solid; border-bottom: lightblue 1px solid; " valign="top">
                                    <table>
                                        <tr >
                                            <td height="30" valign="middle">
                                                &nbsp; &nbsp;<%# DataBinder.Eval(Container.DataItem,"Name") %>     
                                            </td>                    
                                        </tr> 
                                        <tr>
                                             <td>
                                        <asp:DataList ID="dl_min" runat="server" Width="400px" RepeatDirection="Horizontal" RepeatLayout="Flow">
                                            <ItemTemplate>                                    
                                                <input id="CheckRow" runat="server" type="checkbox" value='<%#DataBinder.Eval(Container.DataItem,"PersonID") %>' name="CheckRow"/>
                                                <%#DataBinder.Eval(Container.DataItem,"LoginName") %>&nbsp; &nbsp;&nbsp; &nbsp;
                                            </ItemTemplate>
                                            <AlternatingItemStyle Font-Overline="False" />
                                            <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" />
                                        </asp:DataList> 
                                        </td>
                                        </tr>
                                    </table>
                                </td>
                            </tr>
                        </table> 
                </ItemTemplate>
            </asp:DataList>
      

  2.   

    Page_Load中有没有重新绑定,如果有的话,则checkbox的状态不会保存.