新增按钮事件:
---------------------------------
int index = DataGrid1.Items.Count;
m_ecaDataSet.DataSet.Tables[0].Add(m_ecaDataSet.DataSet.Tables[0].NewRow);
DataGrid1.EditItemIndex = index;
DataGrid1.DataSource = m_ecaDataSet.DataSet.Tables[0];
DataGrid1.DataBind();
----------------------------------
点新增后DataGrid1可出现新行。但点“保存”按钮没有触发DataGrid_UpdateCommand,请问这是为什么??
编辑和删除的时候都没有问题。
private void InitializeComponent()
{
this.btnAdd.Click += new EventHandler(btnAdd_Click);
DataGrid1.CancelCommand += new DataGridCommandEventHandler(this.DataGrid_CancelCommand);
DataGrid1.EditCommand += new DataGridCommandEventHandler(this.DataGrid_EditCommand);
DataGrid1.UpdateCommand += new DataGridCommandEventHandler(this.DataGrid_UpdateCommand);
DataGrid1.DeleteCommand += new DataGridCommandEventHandler(this.DataGrid_DeleteCommand);
DataGrid1.ItemCreated += new DataGridItemEventHandler(this.DataGrid_ItemCreated);
}
---------------------------------
int index = DataGrid1.Items.Count;
m_ecaDataSet.DataSet.Tables[0].Add(m_ecaDataSet.DataSet.Tables[0].NewRow);
DataGrid1.EditItemIndex = index;
DataGrid1.DataSource = m_ecaDataSet.DataSet.Tables[0];
DataGrid1.DataBind();
----------------------------------
点新增后DataGrid1可出现新行。但点“保存”按钮没有触发DataGrid_UpdateCommand,请问这是为什么??
编辑和删除的时候都没有问题。
private void InitializeComponent()
{
this.btnAdd.Click += new EventHandler(btnAdd_Click);
DataGrid1.CancelCommand += new DataGridCommandEventHandler(this.DataGrid_CancelCommand);
DataGrid1.EditCommand += new DataGridCommandEventHandler(this.DataGrid_EditCommand);
DataGrid1.UpdateCommand += new DataGridCommandEventHandler(this.DataGrid_UpdateCommand);
DataGrid1.DeleteCommand += new DataGridCommandEventHandler(this.DataGrid_DeleteCommand);
DataGrid1.ItemCreated += new DataGridItemEventHandler(this.DataGrid_ItemCreated);
}
1.事件丢失。试试重新双击UpdateCommand 事件
2.修改CommandName 值,使得ItemCommand不认别。试试
private void DataGrid1_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName =="保存")
DataGrid1_UpdateCommand(source,e);
}