ASP.net中与GridView相关的问题

本文关键字:问题 GridView net 中与 ASP | 更新日期: 2023-09-27 18:19:34

我已经从数据库绑定了网格视图。。

我有以下代码:

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

现在,我在gridView中有checkBoxdrop-down,当用户从复选框中选择一些行并单击Update Button时,Page_Load事件将触发并调用BindGrid();方法,所选行将被隐藏。

如何在页面加载事件后保留复选框值。

我不想在页面加载中使用IsPostBack属性,因为我已经使用了分页。

我该如何解决我的问题?

ASP.net中与GridView相关的问题

您应该只DataBind GridView if(!Page.IsPostback)。否则,不会触发任何事件,并且ViewState值(如SelectedIndex等)将从DataSource值中覆盖。

http://msdn.microsoft.com/en-us/library/system.web.ui.page.ispostback%28v=VS.100%29.aspx

if(!IsPostBack)
{
   BindGrid();
}

您还应该从以下事件处理程序调用BindGrid

  • PageIndexChanging
  • SelectedIndexChanged
  • Sorting

使用ISpostback。。

if(!IsPostBack)
{
   BindGrid();
}

从分页事件调用bindgrid

function of paging event
{
 BindGrid();
}