How to get inner repeater controls in master detai
Hello,
I have a master detail display in asp.net. I am listing out categories and corresponding subcategories. Near each category there is a check box and for it's corresponding subcategories also there will be check boxes. With check box selecton I should be able to select the categories & subcategories for insertion into table. My problem is, I am getting the categoryid with checkbox selection(by counting the parent repeater items and looping through that), but I am failing to get the subcategory count and details. My output will look like
(checkbox)Category1
(checkbox)SubCategory11.1
(checkbox)SubCategory11.2
(checkbox)SubCategory11.3
(checkbox)Category2
(checkbox)SubCategory12.1
(checkbox)SubCategory12.2
(checkbox)Category3
.
.
.
Code for repeater is
<asp:repeater id="parentRepeater" runat="server">
<HeaderTemplate>
<table border="0" width="100%" cellspacing="2" cellpadding="2">
</HeaderTemplate>
<itemtemplate>
<tr>
<td>
<asp:CheckBox ID="chkIncld" Runat="server" Checked="true" Enabled="true"></asp:CheckBox>
<asp:Label ID="lblCategoryID" Runat="server" text='<%# Container.dataitem("CategoryID") %>' Visible="false">
</asp:Label>
</td>
</tr>
<br>
<asp:repeater id="childRepeater" runat="server" datasource='<%# Container.DataItem.Row.GetChildRows("myrelation1") %>'>
<itemtemplate>
<tr>
<td>
<asp:CheckBox id='chksubid' SubId='<%# Container.dataitem("SD") %>' Runat="server" Checked="true" />
<asp:Label ID="lblSubCategoryID" Runat="server" text='<%# Container.dataitem("SD") %>' Visible="false">
</asp:Label>
<%# Container.DataItem("SubCategoryName") %>
</td>
</tr>
<br>
</itemtemplate>
</asp:repeater>
<FooterTemplate>
</table>
</FooterTemplate>
</itemtemplate>
</asp:repeater><asp:button id="Submit" onclick="Doit" runat="server" Width="60px" Text="Submit" Height="20px"></asp:button><asp:label id="Label1" runat="server" visible="false"></asp:label></form>
And code behind will look like
Public Sub Doit(ByVal Source As Object, ByVal E As EventArgs)
Response.Write("<br>")
Dim i As Integer
Dim iCount As Integer = parentRepeater.Items.Count - 1
Dim _chk As Integer
Dim _lblCateDesc As Label
Dim _lblDescID As Label
Dim _lblID As String
' Spin through all the items and add the checked Parts
For i = 0 To iCount
_chk = (CType(parentRepeater.Items.Item(i).FindControl("c hkIncld"), CheckBox).Checked) * -1
_lblCateDesc = CType(parentRepeater.Items.Item(i).FindControl("lb lCategoryName"), Label)
_lblDescID = CType(parentRepeater.Items.Item(i).FindControl("lb lCategoryID"), Label)
If _chk = 1 Then
_lblID = _lblDescID.Text & " , " & _lblID
End If
Next
End sub
|