0

这是我的代码:当我更改寻呼机的索引时,我得到了正确的数据,但寻呼机页脚消失了:

<asp:GridView ID="GridView1" runat="server" PageSize="4" AllowPaging="true"     AllowSorting="true" AutoGenerateColumns="false" OnRowEditing="GridView1_RowEditing" DataKeyNames="id" OnRowCancelingEdit="GridView1_RowCancelingEdit" AlternatingRowStyle-CssClass="eventRowStyle" OnPageIndexChanging="GridView1_PageIndexChanging" OnPageIndexChanged="GridView1_PageIndexChanged">

代码隐藏:

protected void Page_Load(object sender, EventArgs e)
{
        if (!IsPostBack)
        {
            GridViewDBEntities model = new GridViewDBEntities();
            var query = from p in model.userTbls select p;
            GridView1.DataSource = query;
            GridView1.DataBind();
        }
    }

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridViewDBEntities model = new GridViewDBEntities();
    var query = (from p in model.userTbls orderby p.id ascending select p).Skip((e.NewPageIndex) * GridView1.PageSize).Take(GridView1.PageSize);
    GridView1.PageIndex = e.NewPageIndex;
    GridView1.DataSource = query;
    GridView1.DataBind();
}
4

1 回答 1

1

您可以强制您的寻呼机保持可见!

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
 {
    GridView1.BottomPagerRow.visible = True 

顺便说一句,您已经定义了 pageSize 并将 Paging 设置为 true 所以我认为这会做

    protected void Page_Load(object sender, EventArgs e)
   {
        if (!IsPostBack)
        {
           BindGrid();

        }
    }
       private void BindGrid()
        {
            GridViewDBEntities model = new GridViewDBEntities();
            var query = from p in model.userTbls select p;
            GridView1.DataSource = query;
            GridView1.DataBind();
        }

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  //  GridViewDBEntities model = new GridViewDBEntities();
   // var query = (from p in model.userTbls orderby p.id ascending select //p).Skip((e.NewPageIndex) * GridView1.PageSize).Take(GridView1.PageSize);
    GridView1.PageIndex = e.NewPageIndex;
   // GridView1.DataSource = query;
    //GridView1.DataBind();
     BindGrid();
}

!IsPostback如果您必须实现某些必须编辑网格或插入记录的功能,则删除将导致以后出现问题,无论哪种方式更好的是创建一个Bind方法并根据要求使用它。

于 2013-11-08T09:00:27.033 回答