Gridview using pagertemplate

Discussion in 'ASP .Net' started by Stan SR, Jun 15, 2007.

  1. Stan SR

    Stan SR Guest

    Hi,

    I need to customize a pargertemplate with these items
    a arrow to go back to the 1rst page
    a arrow for the previous page
    a dropdownlist with the page indexes
    a arrow for the new page
    a arrow for the last page.

    The dropdownlist function is okay, but I m blocked with the arrows
    I make something wrong when I set the arrow OnClientClick value or I miss
    something that handles the event.

    Any help ?

    Stan

    Here's my code.

    The aspx part

    <asp:GridView ID="CustomersGridView"
    ondatabound="CustomersGridView_DataBound" runat="server" AllowPaging="True"
    AutoGenerateColumns="False"
    DataSourceID="ObjectDataSource1" AllowSorting="true" Width="700"
    CellPadding="0" BorderWidth="0" CellSpacing="0">
    <HeaderStyle CssClass="headergrille" VerticalAlign="Middle" />
    <RowStyle CssClass="normalrow" />
    <AlternatingRowStyle CssClass="alernaterow" />
    <Columns>
    <asp:BoundField DataField="Nom" HeaderStyle-Width="400" HeaderText="Nom"
    SortExpression="s_libelle" HeaderStyle-CssClass="linkStyleName" />
    <asp:BoundField DataField="Uid" HeaderStyle-Width="300"
    HeaderText="Identificateur" SortExpression="s_uid" />
    </Columns>
    <pagertemplate>
    <div id="pagination">
    <asp:ImageButton ID="fpremier" runat="server"
    ImageUrl="../BACKOFFICE/imgappli/flechepremier.gif" Style="margin:0 5px;" />
    <asp:ImageButton ID="fprecedent" runat="server"
    ImageUrl="../BACKOFFICE/imgappli/flecheprecedent.gif" Style="margin:0 5px;"
    />
    <asp:dropdownlist id="PageDropDownList" autopostback="true"
    onselectedindexchanged="PageDropDownList_SelectedIndexChanged"
    runat="server"/>
    <asp:ImageButton ID="fsuivant" runat="server"
    ImageUrl="../BACKOFFICE/imgappli/flechesuivant.gif" Style="margin:0 5px;" />
    <asp:ImageButton ID="fdernier" runat="server"
    ImageUrl="../BACKOFFICE/imgappli/flechedernier.gif" Style="margin:0 5px;" />
    </div>
    </pagertemplate>
    </asp:GridView>


    The code behind


    protected void PageDropDownList_SelectedIndexChanged(Object sender,
    EventArgs e)
    {
    GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
    DropDownList pageList =
    (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
    CustomersGridView.PageIndex = pageList.SelectedIndex;
    }
    protected void CustomersGridView_DataBound(Object sender, EventArgs e)
    {

    GridViewRow pagerRow = CustomersGridView.BottomPagerRow;
    DropDownList pageList =
    (DropDownList)pagerRow.Cells[0].FindControl("PageDropDownList");
    ImageButton btn;
    if (pageList != null)
    {
    for (int i = 0; i < CustomersGridView.PageCount; i++)
    {
    int pageNumber = i + 1;
    ListItem item = new ListItem(pageNumber.ToString());
    if (i == CustomersGridView.PageIndex)
    item.Selected = true;
    pageList.Items.Add(item);
    }
    }
    if (pageLabel != null)
    {
    int currentPage = CustomersGridView.PageIndex + 1;
    if (currentPage == 1)
    {
    btn =
    (ImageButton)pagerRow.Cells[0].FindControl("fpremier");
    btn.ImageUrl = "../BACKOFFICE/imgappli/flechepremiera.gif";
    btn =
    (ImageButton)pagerRow.Cells[0].FindControl("fprecedent");
    btn.ImageUrl =
    "../BACKOFFICE/imgappli/flecheprecedenta.gif";


    }
    if (currentPage == CustomersGridView.PageCount)
    {
    btn =
    (ImageButton)pagerRow.Cells[0].FindControl("fdernier");
    btn.ImageUrl = "../BACKOFFICE/imgappli/flechederniera.gif";
    btn =
    (ImageButton)pagerRow.Cells[0].FindControl("fsuivant");
    btn.ImageUrl = "../BACKOFFICE/imgappli/flechesuivanta.gif";
    }

    if (currentPage < CustomersGridView.PageCount)
    {
    btn =
    (ImageButton)pagerRow.Cells[0].FindControl("fsuivant");
    btn.OnClientClick =
    "__doPostBack('"+CustomersGridView.ClientID+"','Page$Next')";
    }
    if (currentPage > 1)
    {
    btn =
    (ImageButton)pagerRow.Cells[0].FindControl("fprecedent");
    btn.OnClientClick =
    "__doPostBack('"+CustomersGridView.ClientID+"','Page$Prev')";
    }
    }

    }
     
    Stan SR, Jun 15, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stuart Shay

    Grid View PagerTemplate Skin

    Stuart Shay, Mar 17, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    5,206
    Stuart Shay
    Mar 17, 2006
  2. =?Utf-8?B?RGFiYmxlcg==?=

    add link to existing Gridview 2.0 default pagertemplate

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 20, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    12,254
    =?Utf-8?B?RGFiYmxlcg==?=
    Mar 28, 2006
  3. Nathan Sokalski
    Replies:
    0
    Views:
    404
    Nathan Sokalski
    Jan 11, 2007
  4. Nathan Sokalski

    Accessing the controls in the PagerTemplate when using FormView

    Nathan Sokalski, Jan 11, 2007, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    731
    Nathan Sokalski
    Jan 11, 2007
  5. Nathan Sokalski

    Accessing the controls in the PagerTemplate when using FormView

    Nathan Sokalski, Jan 11, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    273
    Nathan Sokalski
    Jan 11, 2007
Loading...

Share This Page