Solved

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

Posted on 2004-10-15
5
11,202 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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