Urgent , please help-How to get child repeater checkbox status

Discussion in 'ASP .Net' started by Ceema M via DotNetMonster.com, Sep 7, 2005.

  1. Hello all,

    I have a nested repeater, which displays categories(parent repeater) and
    corresponding subcategories(child repeater). Both repeaters have checkboxes.
    When I check category checkbox and subcategory check boxes and click on
    submit button , I have to retrieve the corresponding categoryid and
    subcategory id, so that I can store it to a table. I am getting the
    categoryid but I am failing to get subcategoryid(actually I don't know how to
    retrieve it).

    Thanks
    Ceema

    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


    and my code for this is..


    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("chkIncld")
    , CheckBox).Checked) * -1
    _lblCateDesc = CType(parentRepeater.Items.Item(i).FindControl
    ("lblCategoryName"), Label)
    _lblDescID = CType(parentRepeater.Items.Item(i).FindControl
    ("lblCategoryID"), Label)

    If _chk = 1 Then

    _lblID = _lblDescID.Text & " , " & _lblID



    End If
    Next
    End sub
    ..
    ..
    ..
    Ceema M via DotNetMonster.com, Sep 7, 2005
    #1
    1. Advertising

  2. You'll probably need a nested FOR EACH loop to go with the nested repeaters.
    It's a pain (been there, done that) but it's fairly straightforward.

    --
    Curt Christianson
    site: http://www.darkfalz.com
    blog: http://blog.darkfalz.com



    "Ceema M via DotNetMonster.com" wrote:

    > Hello all,
    >
    > I have a nested repeater, which displays categories(parent repeater) and
    > corresponding subcategories(child repeater). Both repeaters have checkboxes.
    > When I check category checkbox and subcategory check boxes and click on
    > submit button , I have to retrieve the corresponding categoryid and
    > subcategory id, so that I can store it to a table. I am getting the
    > categoryid but I am failing to get subcategoryid(actually I don't know how to
    > retrieve it).
    >
    > Thanks
    > Ceema
    >
    > 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
    >
    >
    > and my code for this is..
    >
    >
    > 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("chkIncld")
    > , CheckBox).Checked) * -1
    > _lblCateDesc = CType(parentRepeater.Items.Item(i).FindControl
    > ("lblCategoryName"), Label)
    > _lblDescID = CType(parentRepeater.Items.Item(i).FindControl
    > ("lblCategoryID"), Label)
    >
    > If _chk = 1 Then
    >
    > _lblID = _lblDescID.Text & " , " & _lblID
    >
    >
    >
    > End If
    > Next
    > End sub
    > ..
    > ..
    > ..
    >
    =?Utf-8?B?Q3VydF9DIFtNVlBd?=, Sep 7, 2005
    #2
    1. Advertising

  3. Ceema,

    If you'd like, take a look at some datagrid code I have on my website,
    www.aboutfortunate.com. If you click the "Code Library" link at the top of
    the page and then use the search box you'll see to search for "Checkbox in
    Datagrid" you'll get some sample code that is very similar to what you need
    to do. In that code I loop through a datagrid's items to find which checkbox
    is checked. Swap the grid for your repeater and it's very similar to what
    you need.

    --
    Sincerely,

    S. Justin Gengo, MCP
    Web Developer / Programmer

    www.aboutfortunate.com

    "Out of chaos comes order."
    Nietzsche
    "Ceema M via DotNetMonster.com" <> wrote in message
    news:...
    > Hello all,
    >
    > I have a nested repeater, which displays categories(parent repeater) and
    > corresponding subcategories(child repeater). Both repeaters have
    > checkboxes.
    > When I check category checkbox and subcategory check boxes and click on
    > submit button , I have to retrieve the corresponding categoryid and
    > subcategory id, so that I can store it to a table. I am getting the
    > categoryid but I am failing to get subcategoryid(actually I don't know how
    > to
    > retrieve it).
    >
    > Thanks
    > Ceema
    >
    > 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
    >
    >
    > and my code for this is..
    >
    >
    > 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("chkIncld")
    > , CheckBox).Checked) * -1
    > _lblCateDesc = CType(parentRepeater.Items.Item(i).FindControl
    > ("lblCategoryName"), Label)
    > _lblDescID = CType(parentRepeater.Items.Item(i).FindControl
    > ("lblCategoryID"), Label)
    >
    > If _chk = 1 Then
    >
    > _lblID = _lblDescID.Text & " , " & _lblID
    >
    >
    >
    > End If
    > Next
    > End sub
    > .
    > .
    > .
    S. Justin Gengo, Sep 7, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KK
    Replies:
    2
    Views:
    557
    Big Brian
    Oct 14, 2003
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,119
    David Schwartz
    Dec 9, 2003
  3. Vannela

    Hoe to get DataList Checkbox status in item template

    Vannela, Dec 16, 2003, in forum: ASP .Net Building Controls
    Replies:
    4
    Views:
    235
    Vannela
    Dec 29, 2003
  4. Ranju
    Replies:
    1
    Views:
    92
    G Roydor
    Aug 5, 2004
  5. Jaiprakash Singh
    Replies:
    1
    Views:
    62
    Nagy László Zsolt
    Feb 13, 2014
Loading...

Share This Page