数据源不支持服务器端数据分页。在asp.net的gridview中进行分页时 [英] The data source does not support server-side data paging. while doing paging in gridview in asp.net
本文介绍了数据源不支持服务器端数据分页。在asp.net的gridview中进行分页时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是.aspx代码
this is .aspx code
<asp:GridView ID="GridView2" runat="server" GridLines="None"
onrowdatabound="GridView2_RowDataBound" align="center"
AllowPaging="True" PageSize="3"
onpageindexchanging="GridView2_PageIndexChanging" AllowSorting="True" >
<AlternatingRowStyle BackColor="White" />
<RowStyle BackColor="#CCCCCC" />
</asp:GridView>
这是C#中的绑定数据代码
this is binding data code in C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Recentinternship();
}
}
protected void Recentinternship()
{
SqlConnection con = new SqlConnection("Data Source=jayraj-pc\\sqlexpress;Initial Catalog=Internship;Integrated Security=True;Pooling=False");
con.Open();
string str = "select B.CompanyLogo as ' ',A.Title,A.InternshipStartDate,A.ApplicationDeadline,A.Duration,A.InternshipCity,A.Category,A.Stipend,A.InternshipID,A.Degree,A.Branch,A.CompanyID,A.Title,A.CompanyName from Internship AS A INNER JOIN Companies AS B ON A.CompanyID=B.CompanyID ";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
SqlDataReader dr = cmd.ExecuteReader();
GridView2.DataSource = dr;
GridView2.DataBind();
//GridView2.BottomPagerRow.Visible = true;
dr.Close();
con.Close();
}
protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
Recentinternship();
}
推荐答案
你必须在这里更改源页面代码..
onpageindexchanging = GridView2_PageIndexChangingto
OnPageIndexChanging =GridView2_PageIndexChanging
You have to change Source page code here..
onpageindexchanging = "GridView2_PageIndexChanging" to
OnPageIndexChanging = "GridView2_PageIndexChanging"
protected void Recentinternship()
{
SqlConnection con = new SqlConnection("Data Source=jayraj-pc\\sqlexpress;Initial Catalog=Internship;Integrated Security=True;Pooling=False");
con.Open();
string str = "select B.CompanyLogo as ' ',A.Title,A.InternshipStartDate,A.ApplicationDeadline,A.Duration,A.InternshipCity,A.Category,A.Stipend,A.InternshipID,A.Degree,A.Branch,A.CompanyID,A.Title,A.CompanyName from Internship AS A INNER JOIN Companies AS B ON A.CompanyID=B.CompanyID ";
// SqlCommand cmd = new SqlCommand(str, con);
SqlDataAdapter da = new SqlDataAdapter(str,con);
DataSet ds = new DataSet();
da.fill(ds,"0");
// SqlDataReader dr = cmd.ExecuteReader();
GridView2.DataSource = ds.Tables["0"].ToString();
GridView2.DataBind();
//GridView2.BottomPagerRow.Visible = true;
dr.Close();
con.Close();
}
看看这个: GridView分页和排序 [ ^ ]
使用数据集/数据表与gridview绑定。
DataReader不允许分页,因为它仅向前
Use Dataset/Datatable for binding with gridview.
DataReader doesn't allow paging because its forward only
这篇关于数据源不支持服务器端数据分页。在asp.net的gridview中进行分页时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文