Expand|Select|Wrap|Line Numbers
- <asp:GridView ID="gridView" runat="server" Style="position: relative" PageSize="5" OnRowCommand="gridView_OnRowCommand" AllowPaging="True" >
- <PagerTemplate>
- <% if (gridView.PageIndex > 0)
- { %>
- <asp:ImageButton ID="imgBtnPrevious" runat="server"
- Style="vertical-align: middle;" img src="pre.jpg"
- CommandArgument='<%# Eval("pre")%>' CommandName="Page" />
- <% } %>
- <%=(gridView.PageIndex * 5) + 1%> - <%=(gridView.PageIndex * 5) + gridView.Rows.Count%>
- <% if (gridView.PageIndex != (gridView.PageCount - 1))
- { %>
- <asp:ImageButton ID="imgBtnNext" runat="server"
- Style="vertical-align: middle;" ImageUrl="next.jpg"
- CommandArgument='<%# Eval("Next")%>' CommandName="Page" />
- <% } %>
- </PagerTemplate>
- </asp:GridView>
in code behind
Expand|Select|Wrap|Line Numbers
- protected void gridView_OnRowCommand(object sender, CommandEventArgs e)
- {
- try
- {
- //Get the current page selected
- int intCurIndex = gridView.PageIndex;
- //Switch-Case to handle to Previous and Next paging
- switch (e.CommandArgument.ToString().ToLower())
- {
- case "prev":
- if (intCurIndex > 0)
- gridView.PageIndex = intCurIndex - 1;
- break;
- case "next":
- if (intCurIndex < gridView.PageCount - 1)
- gridView.PageIndex = intCurIndex + 1;
- break; }
- // popultate the gridview control
- DataSet ds = new DataSet();
- SqlDataAdapter adapPaging = new SqlDataAdapter("select * from customer", "Data Source=OPWFMS-7KYGZ7SB;Initial Catalog=Mayank;User ID=sa;Password=sa");
- adapPaging.Fill(ds);
- gridView.DataSource = ds;
- gridView.DataBind();
- }