Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieve array of checkboxes

Status
Not open for further replies.

stormbind

Technical User
Mar 6, 2003
1,165
0
0
GB
Code:
<asp:GridView ID="GeneratedResults" runat="server">
 <Columns>
   <asp:TemplateField>
      <ItemTemplate>
         <asp:CheckBox ID="ResultSelector" runat="server" />
      </ItemTemplate>
    </asp:TemplateField> 
  </Columns>
</asp:GridView>
<asp:Button ID="Button" Text="Save" runat="server" OnClick="SaveUserChoices"></asp:Button>

Assuming that the above is populated with many checkboxes, how can I retrieve an array that represents those checkboxes?

Code:
protected void SaveUserChoices(object sender, EventArgs e){
 // how do I get the checkboxes?
}


--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
My IIS7 complains that CheckBoxList is not a known element.

Anyway, I don't see how it helps because the scenario I presented is also a constraint. This is because the structure GridView has many nested tables.

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
don't use a gridview just to display a list of check boxes. either use a checkboxlist (html is still horrible, but the server side is easier to work with) or a repeater full control of html, more complex than a check box list on the server side.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
I am using the GridView to display many nested tables, exporting them to HTML, XML, Excel, etc.

I was saving you from looking at them by simplifying the example! Anyway, solution was:
Code:
for( i= ... ++i){
GridViewRow nRow = myGridView.Rows[i];
if((CheckBox)nRow.Cells[1].Controls[1]).Checked){
..
}

--Glen :)

Memoria mihi benigna erit qui eam perscribam
 
GridView to display many nested tables
. there are other ways to nest information without the use of tables. if you only need the tables for formatting/layout purposes (and you can't/don't use css) you can use plain old html within a repeater to build the formatting. this way the presentation of the data doesn't interfere with how the server processes the data.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top