您的位置:首页 > 其它

GridView的简单分页等

2009-10-30 11:19 155 查看
简单分页:

1.设置GridView的AllowPaging="True", PageSize默认为10.

2.触发GridView的PageIndexChanging事件。

3.在后台的PageIndexChanging事件中,写入代码:

protected void GrdPerson_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GrdPerson.PageIndex = e.NewPageIndex;
BindAll();
}

行删除:

在GridView中添加删除列:<asp:CommandField ShowDeleteButton="True" />

触发GridView的RowDeleting事件,并在后台的RowDeleting中,写下删除代码。

删除提示:

触发GridView的RowDataBound事件,后台代码为:

Code

protected void GrdPerson_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((LinkButton)e.Row.Cells[6].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?')");
}
}

}



GridView在没有记录时的显示:
一般,在没有数据时,GridView是不显示在页面中的。网上有没有数据时,显示表头的方法,看起来很复杂,没有去尝试。

我只是设置了 GridView的属性:EmptyDataText="抱歉,没有符合条件的数据"

这样,在没有数据可以显示的时候,就会在GridView的位置,显示该提示。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: