Solved

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

Posted on 2004-10-15
5
11,200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
performance issue in asp web 5 37
RLDC Reporting in Visual studio 11 28
Function after success of Jquery/AJAX action 9 27
Finding Events logs for IIS website that restarts 2 14
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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