i do also have same problem.......i turned off paging but facing the same problem.......plz get me out of it........
Use DataSet/DataTable instead since a DataReader doesn't support paging and sorting capability, the DataReader retrieves a ReadOnly , ForwardOnly stream of data from database..
Here's an example for binding the GridView with DataTable as the DataSource:
private string GetConnectionString()
{
//DBConnection is the name of the connection string that was set up from the web config file
return System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
}
private void BindGridView()
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(GetConnectionString());
try
{
connection.Open();
string sqlStatement = "SELECT * FROM TableName";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
//SHOW GRIDVIEW
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
// NO RECORDS FOUND
}
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindGridView();
}
}
vinz
All-Star
127077 Points
17946 Posts
MVP
Re: The data source does not support server-side data paging.
Jun 19, 2009 06:20 AM|LINK
Use DataSet/DataTable instead since a DataReader doesn't support paging and sorting capability, the DataReader retrieves a ReadOnly , ForwardOnly stream of data from database..
Here's an example for binding the GridView with DataTable as the DataSource:
private string GetConnectionString() { //DBConnection is the name of the connection string that was set up from the web config file return System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; } private void BindGridView() { DataTable dt = new DataTable(); SqlConnection connection = new SqlConnection(GetConnectionString()); try { connection.Open(); string sqlStatement = "SELECT * FROM TableName"; SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection); SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd); sqlDa.Fill(dt); if (dt.Rows.Count > 0) { //SHOW GRIDVIEW GridView1.DataSource = dt; GridView1.DataBind(); } else { // NO RECORDS FOUND } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Fetch Error:"; msg += ex.Message; throw new Exception(msg); } finally { connection.Close(); } } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { BindGridView(); } }MessageBox Controls for WebForms | Blog | Twitter | Linkedin