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.

 
Reply to this topicStart new topic
> help with editable gridview with paging
nixx
post Jun 17 2009, 08:11 PM
Post #1


Member
**

Group: Members
Posts: 138
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
groovicus
post Jun 17 2009, 09:14 PM
Post #2


Hail Groovicus!
******

Group: Site Admin
Posts: 7,900
Joined: 5-June 04
From: Centerville, SD
Member No.: 689



Are you asking how to store results from page to page?


--------------------
Never Argue With Stupid People



Microsoft Senior Student Partner
Go to the top of the page
 
+Quote Post
nixx
post Jun 17 2009, 10:37 PM
Post #3


Member
**

Group: Members
Posts: 138
Joined: 17-January 06
Member No.: 51,078



hey groovicus, I've already figured that out. What I'm trying to achieve is select/deselect all the rows when I click on the checkbox header.

The current gridview displays only 5 rows per page. Checking/unchecking the select all checkbox only checks/unchecks the 5 rows. How do I check all the other rows that aren't shown in the page?

This post has been edited by nixx: Jun 17 2009, 10:37 PM
Go to the top of the page
 
+Quote Post
groovicus
post Jun 17 2009, 11:59 PM
Post #4


Hail Groovicus!
******

Group: Site Admin
Posts: 7,900
Joined: 5-June 04
From: Centerville, SD
Member No.: 689



QUOTE
hey groovicus, I've already figured that out

I'm curious as to how you did that. If I have a collection representing a collection of checked boxes on one page, stored using javascript, that collection is gone when I load the next page, unless I pass the entire collection to the next page in the URL.

I am not explaining this well. HTML is stateless. That means that it can not remember from one page to the next what data has been entered in forms, what links have been clicked, etc. (browsers so this, to an extent). So if I have a page that I click on checkboxes 1,3, and 5, the next page has no way of knowing that. So if you decide to unselect the visible rows, there is no way that you can unselect rows from a different page, because the current page knows nothing about the previous page.

QUOTE
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?

You can't, just using javascript and HTML. You need something on the server end to handle this. The browser can not remember from one page to the next what is happening.


Or else I am not understanding what you want to do.



--------------------
Never Argue With Stupid People



Microsoft Senior Student Partner
Go to the top of the page
 
+Quote Post
nixx
post Jun 18 2009, 12:14 AM
Post #5


Member
**

Group: Members
Posts: 138
Joined: 17-January 06
Member No.: 51,078



Oh I'm using a Session to store the checked items in a list.

Go to the top of the page
 
+Quote Post
groovicus
post Jun 18 2009, 12:30 PM
Post #6


Hail Groovicus!
******

Group: Site Admin
Posts: 7,900
Joined: 5-June 04
From: Centerville, SD
Member No.: 689



One way to do it would be to use an AJAX call to cal your servlet when the "check all" option is checked, then just iterate through the List, setting them to checked (or unchecked, as the case may be).


--------------------
Never Argue With Stupid People



Microsoft Senior Student Partner
Go to the top of the page
 
+Quote Post

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: 8th November 2009 - 02:41 AM


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.