Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In source Code I have took a gridView Control and in that i want to take DataPager Control so where i take that, when i take the control it gives me error. please tell me the solution.
Posted
Updated 5-Dec-12 23:28pm
v2

Hello Sumit,

1. Firstly Drag A GridView Control On .ASPX Page.

2. After That Drag A DatatPager Control On .ASPX Page.

3. After that give the "ID" Of GridView Control to the DataPager control's PageControID.

4. Also Remember to set the Paging Property of GridView to True.

5. After that "OnPageIndexChanged" Function of GridView Give the PageIndex & PageSize Value.
 
Share this answer
 
Comments
sumit kausalye 6-Dec-12 6:14am    
Thanx this is what i expected, Thank you so much
zapbuild 6-Dec-12 6:24am    
your wlcm frnd :)
sumit kausalye 6-Dec-12 6:25am    
please tell me how will give PageIndex and PageSize value?
sumit kausalye 6-Dec-12 6:28am    
:)
zapbuild 6-Dec-12 6:34am    
hey follow this :

pageIndexChanged Function Or Event

int m_PageIndex = GridView.PageIndex;

GridView.PageIndex = m_PageIndex;
now try the following link:


Custom paging with ASP.NET GridView[^]
 
Share this answer
 
Step 1. Create new project in visual studio.

Step 2. Open default.aspx and drag and drop GridView control in design view.

Step 3. Open default.aspx.cs and add following line in using directives:

using System.Data.SqlClient;

Step 4. Open Web.config and add following line just above <system.web>:

<connectionstrings>
<add name="con" connectionstring="Data Source=.\sqlexpress;initial catalog=database_name;integrated security=true;" providername="System.Data.SqlClient">


Step 5. Open properties of GridView, change AllowSorting and AllowPaging property to True.

Step 6. Open default.aspx.cs and add following lines:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
DataView dv = new DataView();
dv = binddata();
GridView1.DataSource = dv;
GridView1.DataBind();
}
private DataView binddata()
{
conn.Open();
SqlDataAdapter adp = new SqlDataAdapter("select data from table", conn);
adp.Fill(ds);
if (ViewState["sortexp"] != null)
{
dv = new DataView(ds.Tables[0]);
dv.Sort = (string)ViewState["sortexp"];
}
else
dv = ds.Tables[0].DefaultView;
conn.Close();
return dv;

}
protected void paging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = binddata();
GridView1.DataBind();
}
protected void sorting(object sender, GridViewSortEventArgs e)
{
ViewState["sortexp"] = e.SortExpression;
GridView1.DataSource = binddata();
GridView1.DataBind();
}
}

Step 7. Open properties of GridView and click on events, change PageIndexChanging to paging and Sorting to sorting.

Step 8. Build the project.
 
Share this answer
 
Comments
sumit kausalye 6-Dec-12 6:04am    
thank for this code, but i want DataPager Control which i can use it for grid view Control
zapbuild 6-Dec-12 6:11am    
hey sumit. Take a look on solution 3 which I have given. i thnik its your solution and also describe about DatatPager Control.
 
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