Dear Friends,
I am having a Data Gridview and had done allow Paging="True"
,on the display i have 10 records and its proper but when i click on the 2nd link at the bottom the gridview is blank.
what could be the mistake.the code is as follows.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
reply.
Thanks & Regards,
Aamir
Loading
Satyapriya NayakPosted Feb 20, 2012, 10:33 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Paging_in_GridView._Default" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Paging_in_GridView
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
bindgrid();
}
void bindgrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
g1.DataMember = "employee";
g1.DataSource = ds;
g1.DataBind();
con.Close();
}
protected void g1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
g1.PageIndex = e.NewPageIndex;
bindgrid();
}
}
}
Thanks
Pramod Kumar NandagiriPosted Feb 20, 2012, 7:29 AM
Where is GridView1.DataSource=dataset
ur code must be
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataSource=dataset (or) any other
GridView1.DataBind();
}
please don't forget to check the thread as "Accepted Answer" if it helps you...