Jump to content
  • Advertisement
Sign in to follow this  

iterate through checkboxes in asp.net

This topic is 4108 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, You guys helped before and maybe you can help me this time too. (using C#) I have a project with: a datagrid, and the datagrid has some columns with values received from a SQL database. the last column of the datagrid, is made of checkboxes. ok so I have added some rows in SQL and they appeared in the datagrid as they should, together with the corresponding checkbox in the last column. my question is however how can I recognise the checkbox's status? so theres checkboxes added dynamically (for each row inserted from SQL) so I cant target each of them by ID, i need some sort of iteration, like: foreach(Checkbox in whatever...) { do..stuff } however the foreach does not work at all. the "whatever" should be the ID of the checkbox? it does not see my control in intellisense or how its called, which means it does not recognise the ID of the checkbox. so I dont know how to target them. They were created from the aspx file like this:
<asp:datagrid ... >


    <asp:Checkbox ID="blabla" runat="server" /> 


so when a new column is made from SQL it receives a checkbox too. how do i target them? Thank you in advance.

Share this post

Link to post
Share on other sites
This is off the top of my head and not tested. I am not a ASP expert so remember that. But this should work.

DataControlFieldCollection collection = dataGrid1.Columns;

foreach(CheckBoxField box in collection)
// What ever you need to do.

Hope that get you going in the right direction. And if it is all wrong, well at least I tried. :)

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!