Link to home
Start Free TrialLog in
Avatar of Mitchell_
Mitchell_

asked on

ASP.NET - Checkbox in repeater to gather a string of ID's

Hi:

I have a repeater I want to add a checkbox to, then do a run through all items in the repeater and collect the ID field and pass it off to another page via the query string for use in a select statement ("SELECT BLAH FROM vwBLAH WHERE RISKID IN (request.querystring("riskstring"))

where the string will be: "3,8,23,65,87"

Here's my repeater - (disregard the riskID URL thing, it will be removed - riskID will need to be binded to the checkbox)

<asp:repeater id="rptDivision" runat="server">
<ItemTemplate>
      <b>
            <%# DataBinder.Eval(Container.DataItem, "DivisionDesc")%>
      </b>
      <HR>
      <asp:repeater id="rptRiskNote" runat="server" DataSource='<%# RiskNoteDataBind(DataBinder.Eval(Container.DataItem,"DivisionID")) %>'>
            <HeaderTemplate>
                  <ul>
            </HeaderTemplate>
            <ItemTemplate>
                  <a href='qreport-edit.aspx?q=<%# request.querystring("q")%>&riskid=<%#DataBinder.Eval(Container.DataItem, "RiskID")%>'>
                        <LI>
                              <%#DataBinder.Eval(Container.DataItem, "Title") & " .."%>
                  </a></span>
                  <br>
            </ItemTemplate>
            <FooterTemplate>
                  </ul>
            </FooterTemplate>
      </asp:repeater><BR />
</ItemTemplate>
<HeaderTemplate>
</HeaderTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:repeater>
ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jnhorst
jnhorst

Tush's code will work.  Just change this:

CheckBox ckb = new CheckBox();
ckb = (CheckBox) rptDivision.Items[i].FindControl("ckbSelect");

to this:

CheckBox ckb = (CheckBox) rptDivision.Items[i].FindControl("ckbSelect");

He gets the points if this works.

John
Avatar of Mitchell_

ASKER

thanks - I will try it tomorrow when I go back to work. :)
ok, I was finally able to try this. I had to convert the code to VB.NEt :

Dim strID As String = ""
        Dim i As Integer

        For i = 0 To rptRiskNote.Items.Count - 1 Step i + 1
            Dim ckb As CheckBox = CType(rptDivision.Items(i).FindControl("ckbSelect"), CheckBox)

            If ckb.Checked Then
                strID += (CType(rptRiskNote.Items(i).FindControl("lblID"), Label)).Text + ","
            End If
        Next

The checkbox is actually in rptRiskNote, not rptDivision - and VS is saying that rptRiskNote doesn't exist - possibly because it's a nested repeater?

sorry, slightly revised:

        Dim strID As String = ""
        Dim i As Integer

        For i = 0 To rptRiskNote.Items.Count - 1 Step i + 1
            Dim ckb As CheckBox = CType(rptRiskNote.Items(i).FindControl("chkSel"), CheckBox)

            If ckb.Checked Then
                strID += (CType(rptRiskNote.Items(i).FindControl("lblID"), Label)).Text + ","
            End If
        Next

        Response.Write(strID)