有关datalist分页后实现编辑异常问题
我用datalist绑定分页数据源
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
page = Request.QueryString[ "page "];
param = Request.CurrentExecutionFilePath + "? ";
CssPage cp = new CssPage(5); //自己写的分页类CssPage 用pagedatasource实现
DataList1.DataSource = cp.GetRecords(consultAdapter.GetConsultByAskOne(mu.UserName), page);//取得分页结果集
DataList1.DataBind();
PageLink.InnerHtml = cp.GetLinkStr(page, param);//取得分页字符串
}
}
在编辑事件中写:
protected void DataList1_EditCommand(object source, DataListCommandEventArgs e)
{
DataList1.EditItemIndex = e.Item.ItemIndex;
DataList1.DataBind();
}
这样点编辑后出现异常,无数据显示;后来猜测是编辑时缺少指明的页数,所以做了下变通:
protected void Page_Load(object sender, EventArgs e)
{
page = Request.QueryString[ "page "];
param = Request.CurrentExecutionFilePath + "? ";
CssPage cp = new CssPage(5); //自己写的分页类CssPage 用pagedatasource实现
DataList1.DataSource = cp.GetRecords(consultAdapter.GetConsultByAskOne(mu.UserName), page);//取得分页结果集
if (!IsPostBack)
{
DataList1.DataBind();
}
PageLink.InnerHtml = cp.GetLinkStr(page, param);//取得分页字符串
}
这样修改后,点编辑就正常显示;但是更新上还是没有完全正确:
protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e)
{
int ID = Convert.ToInt32(DataList1.DataKeys[e.Item.ItemIndex]);
string ask = ((TextBox)e.Item.FindControl( "TextBox1 ")).Text;
DateTim