这是我的代码:当我更改寻呼机的索引时,我得到正确的数据,但寻呼机页脚消失:
<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">
Codebehind:
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();
}
答案 0 :(得分:1)
您可以强制您的寻呼机保持可见!
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
GridView1.BottomPagerRow.visible = True
BTW你已经定义了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
方法并根据要求使用它