2014年7月13日 星期日

[RESOLVED] Error i data paging


when i use to do AllowPaging="true" in my gridview then it use to show me error:


The data source does not support server-side data paging.


Description: An
unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 



Exception Details: System.NotSupportedException: The data source does not support server-side data paging.



Source Error: 











Line 20: 
Line 21: GridView1.DataSource = dr;
Line 22: GridView1.DataBind(); Line 23:
Line 24: }



Hello,


The issue is with datasource. Can you please try with "

ToList()"
 on your result, It should work.


let me know if you have any feedback.



GridView1.DataSource = dr;


is not correct that is what i guess. so please replace as


GridView1.DataSource = ds;


Here the ds is DataSet object also i assume dr as datarow. not so then please allow to be known



Please share what data-source object you are using, for better and quick solution to your problem,


Thanks 



Code behind:


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data.SqlClient;


public partial class Gridview : System.Web.UI.Page

{

void loaduser()

{


conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;

cmd.CommandText = "Select * from CareerTable";

SqlDataReader dr;

dr = cmd.ExecuteReader();


GridView1.DataSource = dr;

GridView1.DataBind();


}

SqlConnection conn = new SqlConnection();

protected void Page_Load(object sender, EventArgs e)

{

conn.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Users\\hp\\Documents\\Visual Studio 2010\\WebSites\\JJBhatt\\App_Data\\Database.mdf;Integrated Security=True;User Instance=True";

if (!Page.IsPostBack)

{


loaduser();

}

}



protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)

{

GridView1.EditIndex = e.NewEditIndex;

loaduser();


}


protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

conn.Open();

SqlCommand cmd = new SqlCommand();

cmd.Connection = conn;


TextBox lname, gender,email,qualification,exp,field,contact;


// fname = (TextBox)GridView1.Rows[e.RowIndex].Cells[1].FindControl("TextBox1");

lname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("lname");

gender = (TextBox)GridView1.Rows[e.RowIndex].FindControl("gender");

email = (TextBox)GridView1.Rows[e.RowIndex].FindControl("email");

qualification = (TextBox)GridView1.Rows[e.RowIndex].FindControl("qualification");

exp = (TextBox)GridView1.Rows[e.RowIndex].FindControl("exp");

field = (TextBox)GridView1.Rows[e.RowIndex].FindControl("field");

contact = (TextBox)GridView1.Rows[e.RowIndex].FindControl("contact");


string name;

name = Convert.ToString((GridView1.DataKeys[e.RowIndex].Value.ToString()));


if (lname != null && gender != null && email != null && qualification != null && exp != null && field != null && contact != null)

{


cmd.CommandText = "Update CareerTable Set LName='" + lname.Text + "',Gender='" + gender.Text + "',Email='" + email.Text + "',Qualification='" + qualification.Text + "',Experience='" + exp.Text + "',Field='" + field.Text + "',Conatct='" + contact.Text + "'
where FName='" + name + "'";

cmd.ExecuteNonQuery();

conn.Close();

Response.Write("Your data is updated");


loaduser();

}


else


{

Response.Write("There is some null data");



}

}

protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)

{

GridView1.SelectedIndex = e.NewSelectedIndex;

loaduser();

}

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)

{

GridView1.EditIndex = -1;

loaduser();

}


protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)

{

conn.Open();

SqlCommand del = new SqlCommand();

del.Connection = conn;


String name;


name = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value);




string strDelete;


strDelete = "delete from CareerTable where FName = '" + name + "'";

del.CommandText = strDelete;

del.ExecuteNonQuery();

conn.Close();

Response.Write("Your data is deleted");

loaduser();

}

protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)

{

e.SortExpression.ToString();

}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

GridView1.PageIndex = e.NewPageIndex;



}

}



//and if possible plz tell me i also couldnt update my data.




computer program seems okay overall. make AllowPaging="false" then reply in thread.




Ammm, aspnet@sams


it is done by using dataadapter.thanks!



dr was actually datareader


沒有留言:

張貼留言