我有一個gridview,我已經啓用分頁和添加事件處理程序。一切工作正常,除了我必須按兩次每個數字更新。在asp.net上的GridView的AllowPaging
下面是我使用用於初始負載正被使用的代碼,以將數據綁定到正被從兩個稱爲datagird代碼和呼叫爲pagechanging事件處理程序
protected void Page_Load(object sender, EventArgs e)
{
query = "SELECT log_id, use_username AS `Username`, log_type AS `Type`, "
+ "log_description AS `Description`, DATE_FORMAT(log_date, '%d-%m-%Y') AS `Date Created`, "
+ "DATE_FORMAT(log_time, '%H:%i') AS `Time Created` FROM log l, users u "
+ "WHERE l.log_userID = u.use_id";
new DatabaseWork().loadGrid(query, tblLog);
if (tblLog.Rows.Count == 0)
{
lblNoData.Visible = true;
}
}
protected void tblLog_PageChanging(object sender, GridViewPageEventArgs e)
{
new DatabaseWork().loadGrid(query, tblLog);
tblLog.PageIndex = e.NewPageIndex;
}
下面上述方法
public void loadGrid(string query, GridView tblGrid)
{
using (DatabaseWork db = new DatabaseWork())
{
using (MySqlCommand cmd = new MySqlCommand(query, db.conn))
{
using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
{
DataSet ds = new DataSet();
da.Fill(ds);
tblGrid.DataSource = ds.Tables[0];
tblGrid.DataBind();
}
}
}
一切工作正常,除了每個頁面編號必須按兩次,我不明白爲什麼。
感謝您的任何幫助。
沒有,有沒有更新面板只是一個普通的ASP形式 – Boardy 2011-04-27 23:36:53