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("risk string"))
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(DataBinde r.Eval(Con tainer.Dat aItem,"Div isionID")) %>'>
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<a href='qreport-edit.aspx?q= <%# request.querystring("q")%> &riskid=<% #DataBinde r.Eval(Con tainer.Dat aItem, "RiskID")%>'>
<LI>
<%#DataBinder.Eval(Contain er.DataIte m, "Title") & " .."%>
</a></span>
<br>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:repeater><BR />
</ItemTemplate>
<HeaderTemplate>
</HeaderTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:repeater>
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("risk
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.
</b>
<HR>
<asp:repeater id="rptRiskNote" runat="server" DataSource='<%# RiskNoteDataBind(DataBinde
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<a href='qreport-edit.aspx?q=
<LI>
<%#DataBinder.Eval(Contain
</a></span>
<br>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:repeater><BR />
</ItemTemplate>
<HeaderTemplate>
</HeaderTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:repeater>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks - I will try it tomorrow when I go back to work. :)
ASKER
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) .FindContr ol("ckbSel ect"), CheckBox)
If ckb.Checked Then
strID += (CType(rptRiskNote.Items(i ).FindCont rol("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?
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)
If ckb.Checked Then
strID += (CType(rptRiskNote.Items(i
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?
ASKER
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) .FindContr ol("chkSel "), CheckBox)
If ckb.Checked Then
strID += (CType(rptRiskNote.Items(i ).FindCont rol("lblID "), Label)).Text + ","
End If
Next
Response.Write(strID)
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)
If ckb.Checked Then
strID += (CType(rptRiskNote.Items(i
End If
Next
Response.Write(strID)
CheckBox ckb = new CheckBox();
ckb = (CheckBox) rptDivision.Items[i].FindC
to this:
CheckBox ckb = (CheckBox) rptDivision.Items[i].FindC
He gets the points if this works.
John