I am new to gridviews, so any help would be most appreciated. Here is my problem:-
I have a form with a GridView and a button.
My gridview is bound to a collection (12000 items) (PageSize = 200) and it has 4 columns:
1st Col =
Expand|Select|Wrap|Line Numbers
- <asp:TemplateField>
- <ItemTemplate>
- <asp:CheckBox ID="_isSelected" runat ="server" />
- </ItemTemplate>
- </asp:TemplateField>
The user can select the multiple rows by clicking the checkbox and then when they click the button on the form I want to loop through the gridview & find which rows have been selected, so that I can be selective on which data I show on another form.
But once the user clicks the button the form is posted back & therefore my gridview is empty, so I can’t do my code as below:-
Expand|Select|Wrap|Line Numbers
- foreach (GridViewRow row in _gridView.Rows)
- {
- //access the check box & find out which items have been selected
- CheckBox checkBox = (CheckBox)row.FindControl("_isSelected");
- if (checkBox != null && checkBox.Checked)
- {
- //create a new entity
- Entity selectedEntity = new Entity();
- //find the entity from the collection using its guid (which is a hidden column)
- selectedEntity = _entities.GetEntityByGuid(row.Cells[3].Text);
- //add the individual entity to the entities collection
- selectedEntities.Add(selectedEntity);
- }
- }
Many thanks
Janet