I need help with storing the changes made in a gridview even after going to another gridview page. I have a gridview with a column for checkboxes. There's also a "check all" checkbox which should, well obviously, check all the items in the gridview.
<asp:GridView ID="gvSearch" runat="server" AutoGenerateColumns="false" CssClass="gv" DataKeyNames="ID" PageSize="5" AllowPaging ="true" OnPageIndexChanging="gvSearch_PageIndexChanging"> <Columns> <asp:TemplateField> <HeaderTemplate> <asp:CheckBox ID="chkSelectAll" runat="server" AutoPostBack="true" OnCheckedChanged="chkSelectAll_CheckedChanged" /> </HeaderTemplate> <ItemTemplate> <asp:CheckBox ID="chkSelect" runat="server" /> </ItemTemplate> <ItemStyle CssClass="gvCell" HorizontalAlign="Center" VerticalAlign="Middle" /> <HeaderStyle CssClass="gvHeader" /> </asp:TemplateField> <asp:BoundField DataField="Name" HeaderText="Skill"> <ItemStyle CssClass="gvCell" HorizontalAlign="Left" VerticalAlign="Middle" /> <HeaderStyle CssClass="gvHeader" /> </asp:BoundField> <asp:BoundField DataField="Description" HeaderText="Description"> <ItemStyle CssClass="gvCell" HorizontalAlign="Left" VerticalAlign="Middle" /> <HeaderStyle CssClass="gvHeader" /> </asp:BoundField> </Columns> <EmptyDataTemplate> <asp:Label ID="lblNoResults" runat="server" Text="No results matching your search were found." /> </EmptyDataTemplate> <RowStyle CssClass="gvRow" /> <AlternatingRowStyle CssClass="gvAlternatingRow" /> <EmptyDataRowStyle CssClass="gvEmpty" /> <PagerSettings Position="TopAndBottom" Mode="NumericFirstLast" PageButtonCount="3" FirstPageText="First" LastPageText="Last" PreviousPageText="Previous" NextPageText="Next"/> <PagerTemplate> <p> <asp:ImageButton ID="cmdFirst" runat="server" ImageUrl="~/IMAGES/first.gif" CommandArgument="first" CommandName="Page" OnCommand="Paginate" ToolTip="First" /> <asp:ImageButton ID="cmdPrevious" runat="server" ImageUrl="~/IMAGES/prev.gif" CommandArgument="prev" CommandName="Page" OnCommand="Paginate" ToolTip="Previous" /> <asp:Label ID="lblPage" runat="server">Page <%= gvEmployees.PageIndex + 1 %> of <%= gvEmployees.PageCount %></asp:Label> <asp:ImageButton ID="cmdNext" runat="server" ImageUrl="~/IMAGES/next.gif" CommandArgument="next" CommandName="Page" OnCommand="Paginate" ToolTip="Next" /> <asp:ImageButton ID="cmdLast" runat="server" ImageUrl="~/IMAGES/last.gif" CommandArgument="last" CommandName="Page" OnCommand="Paginate" ToolTip="Last" /> </p> </PagerTemplate> </asp:GridView>
The code for selecting all
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb;
foreach (GridViewRow gvr in gvSearch.Rows)
{
cb = (CheckBox)gvr.FindControl("chkSelect");
cb.Checked = ((CheckBox)sender).Checked;
}
}The code for populating the gridview
private void showSearchResults()
{
//create list of skills
List<Skill> filteredSkillList = SkillBL.GetFilteredList(qSkillName, qTypeID, qCorporateLevelID,
qCategoryID, qRatingScale, qProviderID, qSkillSetID, qKeyword, qArchived).ToList<Skill>();
//bind list to gvSearch
gvSearch.DataSource = SkillBL.GetFilteredRelatedSkill(filteredSkillList, qRelatedSkill);
gvSearch.DataBind();
}the code for paging
protected void Paginate(object sender, CommandEventArgs e)
{
// get the current page selected
int intCurIndex = gvSearch.PageIndex;
switch (e.CommandArgument.ToString().ToLower())
{
case "first":
gvSearch.PageIndex = 0;
break;
case "prev":
if (intCurIndex == 0)
{
gvSearch.PageIndex = intCurIndex;
}
else
{
gvSearch.PageIndex = intCurIndex - 1;
}
break;
case "next":
gvSearch.PageIndex = intCurIndex + 1;
break;
case "last":
gvSearch.PageIndex = gvSearch.PageCount;
break;
}
}protected void gvSearch_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
e.NewPageIndex = gvSearch.PageIndex;
showSearchResults();
}How do I store the rows that I selected so that when I do something to it, not only the selected rows on the current page are selected but also the selected rows from the other pages?

Help


Back to top









