在ASP.NET中的gridview中没有发生分页。 [英] Paging not happening in gridview in ASP.NET.

查看:93
本文介绍了在ASP.NET中的gridview中没有发生分页。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将分页应用于gridview时,我面临的问题是当我在浏览器中运行程序时,分页不会出现在gridview中。但在视觉工作室中,设计部分会出现分页。当我在浏览器中运行它时,它也没有显示任何错误。



以下是代码



aspx代码



The problem Im facing when i apply paging to gridview is that paging doesnt appear in gridview when i run program in browser. But in visual studio in design section paging appears. It also doesnt show any error when i run it in browser.

below is code

aspx code

 <asp:GridView ID="GridView1" align="center"  OnRowDataBound="GridView1_RowDataBound"  runat="server" AllowPaging="True" 

        PageSize="4" onpageindexchanging="GridView1_PageIndexChanging">
    <HeaderStyle BackColor="ButtonShadow" ForeColor="White" />
    <rowstyle backcolor="LightCyan"  

           forecolor="DarkBlue"

           font-italic="true"/>

        <alternatingrowstyle backcolor="PaleTurquoise"  

          forecolor="DarkBlue"

          font-italic="true"/>
    <pagerstyle CssClass="gridview">

</pagerstyle>
    </asp:GridView>







.cs代码






.cs code

protected void Page_Load(object sender, EventArgs e)
       {
           Getdata();



       }
       protected void Getdata()
       {
           con.Open();
           SqlCommand cmd = new SqlCommand("select  Title, InternshipStartDate, ApplicationDeadline,null as 'Applicants',null as 'Accepted',null as ' ', null as 'Action',null as '   ',InternshipID from Internship  where CompanyID=" + Session["CompanyID"], con);

           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           if (dt.Rows.Count > 0)
           {
               GridView1.DataSource = dt;
               GridView1.DataBind();





           }
           con.Close();

       }
            protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.Header)
           {
               e.Row.Cells[8].Visible = false;
               e.Row.Cells[3].Visible = false;
               e.Row.Cells[4].Visible = false;
           }
          // e.Row.Cells[5].Attributes.Add("onclick", "window.location='Internship_preview.aspx?InternshipID=" + e.Row.Cells[8].Text + "'");
           //e.Row.Cells[6].Attributes.Add("onclick", "window.location='Edit_Internship.aspx?InternshipID=" + e.Row.Cells[8].Text + "'");
           //e.Row.Cells[7].Attributes.Add("onclick", "window.location='Delete_Internship.aspx?InternshipID=" + e.Row.Cells[8].Text + "'");
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               e.Row.Cells[8].Visible = false;
               e.Row.Cells[3].Visible = false;
               e.Row.Cells[4].Visible = false;

               Button btn = new Button();
               //btn.Text = "preview";
               e.Row.Cells[5].Controls.Add(btn);
               btn.CausesValidation = false;
               btn.Text = "preview";
               btn.PostBackUrl = "Internship_preview.aspx?InternshipID=" + e.Row.Cells[8].Text + "";
               btn.CssClass = "button";
               //e.Row.Cells[5].Text = "Preview Internship";



               Button btn1 = new Button();
               //btn.Text = "preview";
               e.Row.Cells[6].Controls.Add(btn1);
               //btn1.CausesValidation = false;
               btn1.Text = "edit";
               btn1.PostBackUrl = "Edit_Internship.aspx?InternshipID=" + e.Row.Cells[8].Text + "";
               //e.Row.Cells[6].Text = "Edit Internship";
               btn1.CssClass = "button";

               Button btn2 = new Button();
               //btn.Text = "preview";
               e.Row.Cells[7].Controls.Add(btn2);

               btn2.CausesValidation = false;
               btn2.Text = "close";
               btn2.PostBackUrl = "Delete_Internship.aspx?InternshipID=" + e.Row.Cells[8].Text + "";
               //e.Row.Cells[7].Text = "Delete Internship";
               btn2.CssClass = "button";

               Label lb1 = new Label();
               e.Row.Cells[3].Controls.Add(lb1);

           }

           }
            protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
            {
                GridView1.PageIndex = e.NewPageIndex;
                Getdata();
            }


            }
         }

推荐答案

分页将在

之后出现1. AllowPaging =True

2.
Paging will appear after
1. AllowPaging="True"
2.
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
            {
                GridView1.PageIndex = e.NewPageIndex;
                Getdata();
            }





3.寻呼数据应该超过PageSize =4



希望这么多事情是必要的。代码完美的地方



3. Paging data should be more than PageSize="4"

Hope so this much things necessary. Where your code is perfect


这篇关于在ASP.NET中的gridview中没有发生分页。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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