数据源不支持服务器端数据分页。 [英] The data source does not support server-side data paging.

查看:57
本文介绍了数据源不支持服务器端数据分页。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.aspx代码

 <   asp: GridView     ID   =  GridView2    runat   =  server    GridLines   =     

< span class =code-attribute> onrowdatabound = GridView2_RowDataBound align = center

PageSize = 4 onpageindexchanging = GridView2_PageIndexChanging ShowHeaderWhenEmpty < span class =code-keyword> = true AllowPaging = true >
< AlternatingRowStyle BackColor = Wh ite / >
< RowStyle BackColor = #CCCCCC / >
< / asp:GridView >







.cs code



 受保护  void  Page_Load( object  sender,EventArgs e)
{
Recentinternship();
}

受保护 void Recentinternship()
{
SqlConnection con = new SqlConnection( 数据来源= jayraj-pc \\sqlexpress;初始目录=实习;综合安全=真;汇总=错误);
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。标题,A.CompanyName来自实习,作为内部联合公司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();

}


受保护 void GridView2_RowDataBound( object sender,GridViewRowEventArgs e)
{
string str = < span class =code-string> 类别 + e.Row.Cells [ 6 ]。文本+ < br />持续时间: + e.Row.Cells [ 4 ]。文本+ < br /> InternshipCity: + e.Row.Cells [ 5 ]。文字+ < br /> Stipend: + e.Row.Cells [ 7 ]。文本+ < br /> InternshipStartDate: + e.Row.Cells [ 2 ]。文本+ < br /> ApplicationDeadline : + e.Row.Cells [ 3 ]。文本+ < br />所需度: + e.Row.Cells [ 9 ]。文字+ < br />必需分支: + e.Row.Cells [ 10 ]文本。
e.Row.Cells [ 1 ]。Text = str;

// e.Row.Cells [1] .Visible = false;
// e.Row.Cells [2] .Visible = false;
e.Row.Cells [ 3 ]。可见= false ;
e.Row.Cells [ 4 ]。可见= false ;
e.Row.Cells [ 5 ]。可见= false ;
e.Row.Cells [ 6 ]。可见= false ;
e.Row.Cells [ 7 ]。可见= false ;
e.Row.Cells [ 8 ]。可见= false ;
e.Row.Cells [ 9 ]。可见= false ;
e.Row.Cells [ 10 ]。可见= false ;
e.Row.Cells [ 11 ]。可见= false ;
e.Row.Cells [ 12 ]。可见= false ;
e.Row.Cells [ 13 ]。可见= false ;


if (GridView2.Rows.Count > < span class =code-digit> 0

{
GridView2.HeaderRow.Cells [ 0 ]。Text = < span class =code-string> ;
GridView2.HeaderRow.Cells [ 1 ]。Text = ;
GridView2.HeaderRow.Cells [ 2 ]。Text = ;




}
图片img = 图片();
img.ID = abc;
img.ImageUrl = e.Row.Cells [ 0 ]。文字;
e.Row.Cells [ 0 ]。Controls.Add(img);

按钮btn = 按钮();
// btn.Text =preview;
e.Row。单元格[ 2 ]。Controls.Add(btn);
btn.CausesValidation = false ;
btn.Text = 查看并应用;
if (Session.Count > 0
{


btn.PostBackUrl = Apply_internship.aspx?InternshipID = + e.Row.Cells [ 8 ]。文字+ & CompanyID = + e.Row.Cells [ 11 ]。文字+ & Title = + e.Row.Cells [ 12 ]。文字+ & CompanyName = + e.Row.Cells [< span class =code-digit> 13 ]。文本+ ;
}

else
{

btn.PostBackUrl = Apply_login.aspx;
}

}

受保护 void GridView2_PageIndexChanging( object sender,GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
Recentinternship();
}

解决方案



请将您的页面加载代码放入!ispostback。

ex:

protected void Page_Load(object sender,EventArgs e)

{

if(!IsPostBack)

{

Recentinternship();

}

}


你正在做什么onrowdatabound =GridView2_RowDataBound显示代码



rowdatabound事件逐行将数据插入gridview,你的分页不工作可能不是geting值。

.aspx code

<asp:GridView ID="GridView2" runat="server" GridLines="None" 

                onrowdatabound="GridView2_RowDataBound" align="center" 

        PageSize="4" onpageindexchanging="GridView2_PageIndexChanging" ShowHeaderWhenEmpty="true" AllowPaging="true" >
                <AlternatingRowStyle BackColor="White" />
                <RowStyle BackColor="#CCCCCC" />
            </asp:GridView>




.cs code

protected void Page_Load(object sender, EventArgs e)
        {
            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_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            string str = " Category :" + e.Row.Cells[6].Text + "<br/>Duration :" + e.Row.Cells[4].Text + "<br/>InternshipCity :" + e.Row.Cells[5].Text + "<br/>Stipend :" + e.Row.Cells[7].Text + "<br/>InternshipStartDate :" + e.Row.Cells[2].Text + "<br/>ApplicationDeadline :" + e.Row.Cells[3].Text + "<br/>Required Degree :" + e.Row.Cells[9].Text + "<br/>Required Branch :" + e.Row.Cells[10].Text;
            e.Row.Cells[1].Text = str;

            //e.Row.Cells[1].Visible = false;
            //e.Row.Cells[2].Visible = false;
            e.Row.Cells[3].Visible = false;
            e.Row.Cells[4].Visible = false;
            e.Row.Cells[5].Visible = false;
            e.Row.Cells[6].Visible = false;
            e.Row.Cells[7].Visible = false;
            e.Row.Cells[8].Visible = false;
            e.Row.Cells[9].Visible = false;
            e.Row.Cells[10].Visible = false;
            e.Row.Cells[11].Visible = false;
            e.Row.Cells[12].Visible = false;
            e.Row.Cells[13].Visible = false;


            if (GridView2.Rows.Count > 0)
            {
                GridView2.HeaderRow.Cells[0].Text = " ";
                GridView2.HeaderRow.Cells[1].Text = " ";
                GridView2.HeaderRow.Cells[2].Text = " ";




            }
            Image img = new Image();
            img.ID = "abc";
            img.ImageUrl = e.Row.Cells[0].Text;
            e.Row.Cells[0].Controls.Add(img);

            Button btn = new Button();
            //btn.Text = "preview";
            e.Row.Cells[2].Controls.Add(btn);
            btn.CausesValidation = false;
            btn.Text = "View and Apply";
            if (Session.Count > 0)
            {


                btn.PostBackUrl = "Apply_internship.aspx?InternshipID=" + e.Row.Cells[8].Text + "&CompanyID=" + e.Row.Cells[11].Text + "&Title=" + e.Row.Cells[12].Text + "&CompanyName=" + e.Row.Cells[13].Text + "";
            }

            else
            {

                btn.PostBackUrl = "Apply_login.aspx";
            }

        }

  protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView2.PageIndex = e.NewPageIndex;
            Recentinternship();
        }

解决方案

hi,
please put your page load code in !ispostback.
ex :
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Recentinternship();
}
}


what you are doing on onrowdatabound="GridView2_RowDataBound" show code

rowdatabound event insert data into gridview row by row and your paging not working might its not geting value.


这篇关于数据源不支持服务器端数据分页。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆