GridView Paging
-
Hello Everybody I have a gridview in my application which values are comes from a DataTable generated in codebehind(means gridview is bind to a DataTable).I want to impliment paging in the gridview. I do it as the code below but it won't work.. protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.Visible = true; GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } Thanks in advance, Happy Coding
A key to every Solution
-
Hello Everybody I have a gridview in my application which values are comes from a DataTable generated in codebehind(means gridview is bind to a DataTable).I want to impliment paging in the gridview. I do it as the code below but it won't work.. protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.Visible = true; GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } Thanks in advance, Happy Coding
A key to every Solution
You are not setting the data source again. You need to set the data source again in the page index changed event, before you do
DataBind()
.protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.Visible = true;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = YourDataTable;
GridView1.DataBind();
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Hello Everybody I have a gridview in my application which values are comes from a DataTable generated in codebehind(means gridview is bind to a DataTable).I want to impliment paging in the gridview. I do it as the code below but it won't work.. protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.Visible = true; GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } Thanks in advance, Happy Coding
A key to every Solution
AS@13 wrote:
I do it as the code below but it won't work..
Very clear... :laugh:
AS@13 wrote:
GridView1.Visible = true; GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind();
When the paging is clicked, the page will postback, where your DataTable will be clear. So you have to generate the DataTable again and assign it to the GridView. Call the DataBind now.
[Venkatesh Mookkan] My: Website | Yahoo Group | Blog Spot
-
Hello Everybody I have a gridview in my application which values are comes from a DataTable generated in codebehind(means gridview is bind to a DataTable).I want to impliment paging in the gridview. I do it as the code below but it won't work.. protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.Visible = true; GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } Thanks in advance, Happy Coding
A key to every Solution
Hi, protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; Gridview1.DataSource = tblData; //this should be your data table GridView1.DataBind(); } The logic written above will work if and only if you declare your data table as shared, (i.e) shared tblData as DataTable Check out this
-
You are not setting the data source again. You need to set the data source again in the page index changed event, before you do
DataBind()
.protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.Visible = true;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource = YourDataTable;
GridView1.DataBind();
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions