1

.net の DataTable に関連する問題があります。私はpage_loadでデータテーブルを埋めようとしています.その部分は問題ありませんデータテーブルは正しくデータで埋められています. しかし、ページ上のボタンをクリックすると...再びデータテーブルを埋めようとすることに気付きましたが、これは時間のかかる作業です...ブラウザでサイトを開いたときに一度だけデータテーブルを埋める必要があります..クリックするたびにではありません...テーブルに大量のデータがあるため、データテーブルにロードするのに時間がかかります..plzは私を助けてください...これが私のコードです:

protectd void Page_Load(object sender, EventArgs e)
{
        cnn.ConnectionString= ConfigurationManager.ConnectionStrings["con"].ConnectionString;

      //  if (this.IsPostBack == true)
        {
            dr1 = TableUtoP(); 
            dtWordsList.Load(dr1);
       }
}

OleDbDataReader TableUtoPunj(String ArrWord)
    {
        if (cnn.State == ConnectionState.Open)
        {
            cnn.Close();
        }
        cnn.Open();
        OleDbCommand cmd = new OleDbCommand();
        cmd.CommandText = "SELECT U, P from UtoP";
        cmd.Connection = cnn;
        OleDbDataReader dr = cmd.ExecuteReader();
        return dr;
    }
4

2 に答える 2

3

次のように、ページがポストバックしているかどうかを確認する必要があります。

protected void Page_Load(object sender, EventArgs e)
{
    cnn.ConnectionString= ConfigurationManager.ConnectionStrings["con"].ConnectionString;

    if(!IsPostBack)
    {
        // This will only happen when the page is first loaded, as the first time is not considered a post back, but all others are
        dr1 = TableUtoP(); 
        dtWordsList.Load(dr1);
    }
}
于 2013-08-09T20:42:34.977 に答える
0

PostBack でない場合にのみ dataTable に入力します...

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        //TO DO: Make the call to fill the data table here
   }
}
于 2013-08-09T20:43:59.613 に答える