启用分页后,回发后网格视图消失

时间:2013-02-23 15:29:01

标签: asp.net data-binding gridview datatable

我的问题是,当我单击按钮将数据加载到gridview时,它工作正常。但是当我点击一个新页面时,gridview消失了;然后,我必须再次单击该按钮才能看到它。

有人有任何建议吗?

这是c#:

SqlConnection sqlConnection1 = new SqlConnection(strSQLConnection1);
SqlConnection sqlPopGrid = new SqlConnection(strSQLConnection1);
SqlCommand sqlCommandPopGrid = new SqlCommand("select id, quote, author from TABLE", sqlConnection1);

DataTable dt = new DataTable();

sqlPopGrid.Open();
SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(sqlCommandPopGrid);
sqlDataAdapter1.Fill(dt);

if (dt.Rows.Count > 0)
{
   grd1.DataSource = dt;
   grd1.DataBind();
}

sqlPopGrid.Close();

这是aspx:

<asp:GridView runat="server" AllowPaging="True" AllowSorting="True"
              AutoGenerateSelectButton="True" ID="grd1" 
              OnPageIndexChanging="grd1_PageIndexChanging" 
              OnSelectedIndexChanged="grd1_SelectedIndexChanged"  
              OnSorting="grd1_Sorting">
      <PagerSettings PageButtonCount="5"></PagerSettings>
</asp:GridView>

顺便说一句,如果有任何用途,我正在使用asp.net 4.0。

0 个答案:

没有答案