I guess your requirement is to show paging options like First Next Previous Last in gridview. if that is the case then your best option would be to use the
GridView PagerSettings Mode property. you need to set the Pagersettings mode property to "NextPreviousFirstLast".
Please find the sample implementation
<asp:GridView ID="GridView5" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="true" PageSize="1"
OnPageIndexChanging="GridView5_PageIndexChanging">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField HeaderText="ID" DataField="ID" />
<asp:BoundField HeaderText="Item" DataField="Item" />
<asp:BoundField HeaderText="FirstName" DataField="FirstName" />
<asp:BoundField HeaderText="EmployeeSalary" DataField="EmployeeSalary" />
</Columns>
<PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" PreviousPageText="Previous" Visible="true"
NextPageText="Next" LastPageText="Last" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
</asp:GridView>
C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Assign the data to GridView
GridView5.DataSource = this.Get_TotalDetails();
//Bind the Grid
GridView5.DataBind();
}
}
//Populate some dummy data
public DataTable Get_TotalDetails()
{
DataTable dt = new DataTable();
DataRow dr;
string ID = "70123,28123123,70123123,5212313,4012313";
string Item1 = "Bat,Ball,Stumps,Caps,TeamBand";
string FirstName = "Name1,Name2,Name3,Name4,Name5";
string EmployeeSalary = "7000,28876,3498,5232,40456";
//string SelectedField = "True,False,False,False,True";
string[] list4 = ID.Split(',');
string[] list1 = Item1.Split(',');
string[] list2 = FirstName.Split(',');
string[] list3 = EmployeeSalary.Split(',');
//string[] list3 = SelectedField.Split(',');
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("Item", typeof(string));
dt.Columns.Add("FirstName", typeof(string));
dt.Columns.Add("EmployeeSalary", typeof(int));
for (int i = 0; i < list4.Length; i++)
{
dr = dt.NewRow();
dr["ID"] = list4[i];
dr["Item"] = list1[i];
dr["FirstName"] = list2[i];
dr["EmployeeSalary"] = list3[i];
dt.Rows.Add(dr);
}
return dt;
}
/// <summary>
/// Handles the PageIndexChanging event of the GridView5 control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="GridViewPageEventArgs"/> instance containing the event data.</param>
protected void GridView5_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView5.PageIndex = e.NewPageIndex;
//Assign your datasource here.
//If you are having data fetching method in any other method call that method here
GridView5.DataSource = this.Get_TotalDetails();
GridView5.DataBind();
}
You can see the rendered output here
http://i.imgur.com/IvRJNS9.png
Please mark my reply as answer if it helps to resolve your problem
Thanks,
A2H
My Blog
Venky.Net, if this helps please login to Mark As Answer. | Alert Moderator