Solved

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

Posted on 2004-10-15
5
11,196 Views
Last Modified: 2012-06-27
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>
0
Comment
Question by:Mitchell_
  • 3
5 Comments
 
LVL 18

Accepted Solution

by:
tusharashah earned 500 total points
ID: 12322689
Add a CheckBox to your Repeater and then you can loop your repeater control like following to retrieve values:

---------------------------------------------------------------------------------------------------------------------------------------
string strID = "";
for(int i=0; i < rptDivision.Items.Count; i++)
  {
      CheckBox ckb = new CheckBox();
      ckb = (CheckBox) rptDivision.Items[i].FindControl("ckbSelect");

      if(ckb.Checked)
      {
            strID += ( (Label) rptDivision.Items[i].FindControl( "lblID" ) ).Text + ",";
                }
}
---------------------------------------------------------------------------------------------------------------------------------------

-tushar
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12322726
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
0
 

Author Comment

by:Mitchell_
ID: 12338734
thanks - I will try it tomorrow when I go back to work. :)
0
 

Author Comment

by:Mitchell_
ID: 12369752
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?

0
 

Author Comment

by:Mitchell_
ID: 12369776
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)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now