Gridview using pagertemplate

S

Stan SR

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')";
}
}

}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top