使用GridView的換頁時
要注意一些事
這樣的目的主要是減少網頁對伺服器的quary
程式碼如下:
protected void Page_Init(object sender, EventArgs e)
{
if (!IsPostBack)
{
getData();
}
}
protected void gvUser_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.gvUser.SelectedIndex = -1;
this.gvUser.PageIndex = e.NewPageIndex;
this.gvUser.DataSource = ViewState["ajaxCA0100"];
this.gvUser.DataBind();
}
protected void gvUser_SelectedIndexChanged(object sender, EventArgs e)
{
using (var dt = (DataTable)ViewState["xxx"])
{
var tR = dt.Select("使用者ID='" + this.gvUser.SelectedValue + "'");
if (tR.Length > 0)
{
string s = "";
for (int i = 1; i <= 4; i++)
{
s += ",'" + tR[0][i].ToString() + "'";
}
csService.setScript(this, "getSelected('" + this.gvUser.SelectedValue + "'" + s + ");");
}
}
}
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] myState = (object[])savedState;
ViewState["ajaxCA0100"] = myState[1];
}
}
protected override object SaveViewState()
{
return new object[]{
base.SaveViewState(),
ViewState["xxx"]
};
}
留言列表