consultancy chorley ASP.NET Server Side Scripting Wigan
Website Development Radcliffe

A Coder's Notes

Email :
bespoke invoice systems Standish Information Technology Advice Worsley
    development systems Ramsbottom
data manipulation Farnworth access databases Whitefield SQL connections Atherton
online accessible software Leyland software compatible Coppull

Get connected and Online Tottington
remote management Makerfield code and design Aspull

ASP.Net Checkboxes In Repeaters - The Easy Way - 15/03/2012

ASP can be complex, and I like simple.  So this is how to put a simple checkbox into a repeater WITHOUT having ASP.Net know about it.  Is that a problem? point ASP.Net to the postback data to find what you're looking for.

So, the repeater...which has already been bound to some data typically from a database...

<asp:repeater id = "mygrid" runat = "server">

<input type = "checkbox" 
       id = "emailf"
       name = "emailf"
       value = "<%# container.dataitem("emailf") %>"

<%# container.dataitem("namef") %>


So when the repeater runs there's be lots and lots of tick boxes...but they' all have the same name, in this instance "emailf".  Oh do I get the information back as to which boxes has been ticked???

Note in the repeater the "value" will be different for each check box, because this has been populated from the bound data, probably an SQL query results.  What HTML and browsers do is say...

"Well, OK I've 20 check boxes here ALL with the same ID, so if say 3 of the check boxes are ticked I'll send back the "values" from the ticked checkboxes"

These values are returned under the collective name of the checkboxes, "emailf" and the values are returned with a comma to sepearte them.  So to get these values I simply use...


Which will return a comma separated string of all the values of the boxes that were ticked, for example...,,,

Now you have a string with all the values that were ticked...manipulate the string as you see fit.

Post A Comment

Name Comment
programming services specialist
Valid XHTML 1.0 Transitional