Welcome Guest ( Log In | Click here to Register a free account now! )
Welcome to Bleeping Computer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.
Jun 17 2009, 08:11 PM
Post
#1
|
|
|
Member ![]() ![]() Group: Members Posts: 140 Joined: 17-January 06 Member No.: 51,078 |
Hi,
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. CODE <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 CODE 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 CODE 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 CODE 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; } } CODE 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? |
|
|
|
nixx help with editable gridview with paging Jun 17 2009, 08:11 PM
groovicus Are you asking how to store results from page to p... Jun 17 2009, 09:14 PM
nixx hey groovicus, I've already figured that out. ... Jun 17 2009, 10:37 PM
groovicus
I'm curious as to how you did that. If I have... Jun 17 2009, 11:59 PM
nixx Oh I'm using a Session to store the checked it... Jun 18 2009, 12:14 AM
groovicus One way to do it would be to use an AJAX call to c... Jun 18 2009, 12:30 PM![]() ![]() |
| Lo-Fi Version | Time is now: 24th November 2009 - 04:28 PM |