Sign in to follow this  

iterate through checkboxes in asp.net

This topic is 3745 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 ... >

<columns>
...
</columns>

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

</asp:datagrid>

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. :)
theTroll

Share this post


Link to post
Share on other sites

This topic is 3745 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this