Subject: Re: Best practice for checkboxes in repeaters
Date: Wed, 19 Nov 2003 09:12:36 +0100
Lines: 111
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <
[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
NNTP-Posting-Host: 195.41.96.158
Path: cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.
phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontrols:16287
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
Hi Mike,
It does not, no - What you are getting from your iteration is a boolean
telling you whether or not the checkbox has been checked, not exactly WHAT
is checked.
If my repeater contained eg. a list of records i wanted to delete from, I
would have to store the recordset i initially bound to the repeater, and use
that in connection with the index you're finding, to find out e.g. the
unique ID of the record(s) selected.
Let me give you an ASP example: In asp, I would render a list of records to
the client, with checkboxes named "checked_delete_id_XYX", with XYX being
the unique ID of the record i wanted to delete. Upon postback, i would
iterate through the forms collection to find all checkboxes starting with
"checked_delete_id_", and run my "business logic" (in this case, deleting a
record) on this ID.
Also, you use an index into Controls (Controls(X)), which i consider bad
practice .. It's hard to read unless you know exactly how your codefront
looks, and if someone was to add an additional checkbox to the codefront,
the code would still work but the result completely wrong.
..Or is my approach just completely wrong?
Cheers,
/Thomas
"Mike Moore [MSFT]" said:
Hi Thomas,
I put a checkbox on a repeater and added a button (outside of the
repeater). In the button's server-side click event, I iterated through the
repeater to get the values of each check box. Here's a code snippet.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 0 To Repeater1.Items.Count - 1
Response.Write(CType(Repeater1.Items(i).Controls(1),
WebControls.CheckBox).Checked & "<br>")
Next i
End Sub
In my case the check box was at position Controls(1). You may need to
adjust that number.
Does this answer your question?
Thank you, Mike
Microsoft, ASP.NET Support Professional
Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.
This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Thomas Nielsen [AM Production A/S]" <
[email protected]>
Subject: Best practice for checkboxes in repeaters
Date: Tue, 18 Nov 2003 12:32:28 +0100
Lines: 19
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <
[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
NNTP-Posting-Host: 195.41.96.158
Path:
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.