Solved

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

Posted on 2004-10-15
5
11,194 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
Comment Utility
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
Comment Utility
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_
Comment Utility
thanks - I will try it tomorrow when I go back to work. :)
0
 

Author Comment

by:Mitchell_
Comment Utility
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_
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

17 Experts available now in Live!

Get 1:1 Help Now