我用GridView分页,可是点下一页之后,上一页的按钮就不见了。怎么办?

数据是动态绑定的,单是应该跟分页关系不大,分页能分,单就是现在测试数据就两页,点下页之后,就没有点不回上一页了,分页导航都不见了。求高手赐教~~~~... 数据是动态绑定的,单是应该跟分页关系不大,分页能分,单就是现在测试数据就两页,点下页之后,就没有点不回上一页了,分页导航都不见了。求高手赐教~~~~ 展开
 我来答
zhubin_wyn
2011-10-26 · TA获得超过175个赞
知道小有建树答主
回答量:216
采纳率:100%
帮助的人:257万
展开全部
我给你一个GridView的应用示例,你看看,希望对你有帮助:
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OASys.BLL;
using OASys.Models;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
public UserInfoManager info = new UserInfoManager();

/// <summary>
/// 窗体加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadInfo();
}
}

/// <summary>
/// 加载用户信息的方法
/// </summary>
private void LoadInfo()
{
List<UserInfo> users =new List<UserInfo>();
foreach (UserInfo user in info.GetAllUserInfo())
{
if (user.Gender == 1)
{
user.DepartId.sex = "男";
}
else
{
user.DepartId.sex = "女";
}
users.Add(user);
}
gdvUserInfo.DataSource =users;
gdvUserInfo.DataBind();
}

/// <summary>
/// 分页事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gdvUserInfo.PageIndex = e.NewPageIndex;
LoadInfo();
}

/// <summary>
/// 删除信息事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id =gdvUserInfo.DataKeys[e.RowIndex].Value.ToString();
if (info.DeleteUserInfoById(id) > 0)
{
this.lblMessage.Text = "删除成功!";
LoadInfo();
}
else
{
this.lblMessage.Text = "删除失败!";
LoadInfo();
}
}

/// <summary>
/// 编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowEditing(object sender, GridViewEditEventArgs e)
{
gdvUserInfo.EditIndex = e.NewEditIndex;
LoadInfo();
}

/// <summary>
/// 取消编辑事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gdvUserInfo.EditIndex = -1;
LoadInfo();
}

/// <summary>
/// 更新事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string userId = gdvUserInfo.DataKeys[e.RowIndex].Value.ToString();
TextBox txtUserId = (TextBox)gdvUserInfo.Rows[e.RowIndex].Cells[0].FindControl("txtUserId");
TextBox txtUserName = (TextBox)gdvUserInfo.Rows[e.RowIndex].Cells[0].FindControl("txtUserName");
TextBox txtPassWord = (TextBox)gdvUserInfo.Rows[e.RowIndex].Cells[0].FindControl("txtPassWord");
if (txtUserName != null && txtPassWord != null)
{
try
{
UserInfo user = info.GetUserInfoById(userId);
user.UserName = txtUserName.Text.ToString();
user.Password = txtPassWord.Text.ToString();
if (info.ModifyUserInfo(user) > 0)
{
this.lblMessage.Text = "修改成功!";
gdvUserInfo.EditIndex = -1;
LoadInfo();
}
else
{
this.lblMessage.Text = "修改失败!";
gdvUserInfo.EditIndex = -1;
LoadInfo();
}
}
catch (Exception)
{

this.lblMessage.Text = "修改失败!";
gdvUserInfo.EditIndex = -1;
LoadInfo();
}
}
}

/// <summary>
///
/// 光棒事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gdvUserInfo_RowDataBound(object sender, GridViewRowEventArgs e)
{
for (int i = 0; i < gdvUserInfo.Rows.Count; i++)
{
if (gdvUserInfo.Rows[i].RowType == DataControlRowType.DataRow)
{
gdvUserInfo.Rows[i].Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#9cf'");
gdvUserInfo.Rows[i].Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
}
chwaudrm
2011-10-26 · 贡献了超过132个回答
知道答主
回答量:132
采纳率:0%
帮助的人:51.3万
展开全部
需要重新绑定数据源(整个t表), 你的dt是数据源吗? uyg堡g堡cl悌pコ┱wコ纽
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式