Computer Help and Spyware Removal Computer Help and Spyware Removal Computer Help and Spyware Removal Computer Help Forums Windows Startup Programs Database Virus, Spyware, and Malware Removal Guides Computer Tutorials Uninstall Database File Database Computer Glossary Computer Resources
 

Welcome Guest ( Log In | Click here to Register a free account now! )



Register a free account to unlock additional features at BleepingComputer.com
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.
Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

> help with editable gridview with paging
nixx
post 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?
Go to the top of the page
 
+Quote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 24th November 2009 - 04:28 PM


Advertise   |   About Us   |   Terms of Use   |   Privacy Policy   |   Contact Us   |   Site Map   |   Chat   |   Tutorials   |   Uninstall List
Discussion Forums   |   The Computer Glossary   |   Resources   |   RSS Feeds   |   Startups   |   The File Database   |   Virus Removal Guides

© 2003-2009 All Rights Reserved Bleeping Computer LLC.