Click here to Skip to main content
15,909,498 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i am new in development field..so pls solve my problem..my qustion is...how i perform paging in gridview..when i set all the properties of gridview....something i m missing..here there is data in table but the button of pager dont perform any operation..help me out..how the data will pass if we click on particular button..anyone pls help me out....even nxt ya pervious button is clicked that doesnt show any data at all....
Posted

You need to write the following code in page index changing event

C#
Dataset ds = (DataSet)Session["dsTable"];
Gridview1.PageIndex = e.NewPageIndex;
Gridview1.DataSource = ds;
Gridview1.DataBind();
 
Share this answer
 
v2
Comments
keshav kumar jha 21-Sep-11 8:14am    
thnx...i got the solution...thnx a lot
Hi see below

<asp:datagrid id="dgemployees" runat="server" xmlns:asp="#unknown">
AutoGenerateColumns="False" Width="100%" CssClass="Grid" HeaderStyle-BackColor="#e5ecf3"
HeaderStyle-Font-Bold="true"
OnEditCommand="dgemployees_EditCommand1"
AllowSorting="True"
OnSortCommand="dgemployees_SortCommand"
BorderStyle="None" >
<columns> <asp:boundcolumn datafield="EmpUID" headertext="EmpUID" sortexpression="EmpUID">
<asp:boundcolumn datafield="EmployeeName" headertext="Name" sortexpression="EmployeeName">
<asp:boundcolumn datafield="EmpID" headertext="EmpCode">
<asp:boundcolumn datafield="Fullgender" headertext="Gender">
<asp:boundcolumn datafield="HireDate" headertext="HireDate" dataformatstring="{00:MM/dd/yyyy}">
<asp:boundcolumn datafield="Department" headertext="Department" sortexpression="Department">
<asp:boundcolumn datafield="EmployeeStatus" headertext="Status" visible="false">
<asp:boundcolumn datafield="JobStatus" headertext="JobStatus">
<asp:editcommandcolumn edittext="Open Profile" headertext="View/Edit">



In Code page:

Public static int numberDiv;
protected void dgemployees_SortCommand(object source, DataGridSortCommandEventArgs e)
{
DataSet dsemps = new DataSet();
dsemps = csHRObj.dsGetemployees();
DataView dv = new DataView(dsemps.Tables[0]);

if ((numberDiv % 2) == 0)
dv.Sort = e.SortExpression + " " + "ASC";
else
dv.Sort = e.SortExpression + " " + "DESC";
numberDiv++;
dgemployees.DataSource = dv;
dgemployees.DataBind();
}
 
Share this answer
 
Comments
P.Salini 21-Sep-11 7:25am    
I think its the code for sorting
the question is about paging
better to go trhoug all the properties of grid whether u mentioned allopaging and check PageSize too . if u r still u r not getting then plz chk:


http://support.microsoft.com/kb/305271
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900