0

我的问题是,当我单击按钮将数据加载到 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。

4

0 回答 0