[导入]关于DATAGRID数据更改时点2次/行号跟不准/失去焦点/丢失e等一系列问题的解决办法:
首先把数据连接/dataadater等信息全放到void bindgrid中,其他地方不用if(!ISPOSTBACK),在PAGELOAD的时候只用个
if (!IsPostBack)
{
BindGrid();
}
---------------------------------------------------------------------------------
例如: private void Page_Load(object sender, System.EventArgs e)
{ if (!IsPostBack)
{BindGrid();}
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ DataGrid1.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ DataGrid1.EditItemIndex = -1;
BindGrid();
}
void BindGrid()
{ oleDbDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
}
文章来源:http://dotnet.mblogger.cn/zeusvenus/posts/7260.aspx
if (!IsPostBack)
{
BindGrid();
}
---------------------------------------------------------------------------------
例如: private void Page_Load(object sender, System.EventArgs e)
{ if (!IsPostBack)
{BindGrid();}
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ DataGrid1.EditItemIndex = e.Item.ItemIndex;
BindGrid();
}
private void DataGrid1_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{ DataGrid1.EditItemIndex = -1;
BindGrid();
}
void BindGrid()
{ oleDbDataAdapter1.Fill(dataSet11);
DataGrid1.DataBind();
}
文章来源:http://dotnet.mblogger.cn/zeusvenus/posts/7260.aspx