Datagrid Update and Cancel events fire as Edit

Datagrid Update and Cancel events fire as Edit

Post by Stev » Sat, 28 Feb 2004 02:21:36


have a datagrid that is created at run time

DataGrid dgG = new DataGrid();
BoundColumn bcB;

dgG.CellPadding = 5;
dgG.CellSpacing = 0;
dgG.GridLines = GridLines.Both;
dgG.CssClass = "SectionTableLines";
dgG.DataKeyField = "PlanWorkOrderID";
dgG.ID = DataSetName + "." + Constants.datagrid + "." + "0";

dgG.HeaderStyle.CssClass = "SectionHeader";


bcB = new BoundColumn();

bcB.DataField = "WorkOrder";
bcB.HeaderText = "WorkOrder";
dgG.Columns.Add(bcB);

dgG.AutoGenerateColumns = false;

EditCommandColumn eccE = new EditCommandColumn();
eccE.EditText = "Edit";
eccE.CancelText = "Cancel";
eccE.UpdateText = "Update";
eccE.HeaderText = "Edit";
eccE.ButtonType = ButtonColumnType.LinkButton;
eccE.ItemStyle.CssClass = "TxtBox";

dgG.Columns.Add(eccE);
dgG.EnableViewState =false;


ButtonColumn btncBC = new ButtonColumn();
btncBC.HeaderText = "Delete";
btncBC.ButtonType = ButtonColumnType.LinkButton;
btncBC.Text = "Delete";
btncBC.CommandName = "Delete";

dgG.Columns.Add(btncBC);


dgG.DataSource = dtT;
dgG.DataBind();

dgG = qabQA.makeWorkOrder(dstForm1370.Tables[Constants.WorkOrder]);
dgG.EditCommand += new DataGridCommandEventHandler(dgG_EditCommand);
dgG.DeleteCommand += new DataGridCommandEventHandler(dgG_DeleteCommand);
dgG.UpdateCommand += new DataGridCommandEventHandler(dgG_UpdateCommand);
dgG.ItemCommand += new DataGridCommandEventHandler(dgG_ItemCommand);
dgG.CancelCommand += new DataGridCommandEventHandler(dgG_CancelCommand);
tcC.Controls.Add(dgG); // tcC is a table cell


The event handlers are the standard stuff.

private void dgG_EditCommand(object source, DataGridCommandEventArgs e)
{
Control ctlC;
string sDGID;

sDGID = Constants.WorkOrder + "." + Constants.datagrid + "." + "0";

ctlC = FindControl(sDGID);

((DataGrid)ctlC).EditItemIndex = e.Item.ItemIndex;

BindGrid();

}

private void dgG_DeleteCommand(object source, DataGridCommandEventArgs e)
{
DataTable dtT;
int dgPK;

dtT = dstForm1370.Tables[Constants.WorkOrder];
dgPK = (int)e.Item.ItemIndex;
dtT.Rows[dgPK].Delete();

BindGrid();
}

private void dgG_ItemCommand(object source, DataGridCommandEventArgs e)
{
DataTable dtT;
int dgPK;

if (((LinkButton)e.CommandSource).CommandName == "Delete")
{
dtT = dstForm1370.Tables[Constants.WorkOrder];
dgPK = (int)e.Item.ItemIndex;
dtT.Rows[dgPK].Delete();

BindGrid();
}
else
{
}
}

private void dgG_UpdateCommand(object source, DataGridCommandEventArgs e)
{
DataTable dtT;
string sDGID;
int iPK;

dtT = dstForm1370.Tables[Constants.WorkOrder];

sDGID = Constants.WorkOrder + "." + Constants.datagrid + "." + "0";

iPK = (int)e.Item.ItemIndex;

dtT.Rows[iPK]["WorkOrder"] = ((TextBox)(e.Item.FindControl(sDGID))).Text;

BindGrid();
}

private void BindGrid()
{
DataTable dtT;
Control ctlC;
string sDGID;

dtT = dstForm1370.Tables[Constants.WorkOrder];

sDGID = Constants.WorkOrder + "." + Constants.datagrid + "." + "0";

ctlC = FindControl(sDGID);

((DataGrid)ctlC).DataSource = dtT;
((DataGrid)ctlC).DataBind();
Session["Form1370DataSet"] = dstForm1370.Copy();
}

private void dgG_CancelCommand(object source, DataGridCommandEventArgs e)
{
 
 
 

Datagrid Update and Cancel events fire as Edit

Post by Alvin Brun » Thu, 04 Mar 2004 00:06:06

our post went unanswered. Have you resolved this issue?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Steve" < XXXX@XXXXX.COM > wrote in message
news:u4Ll3zI$ XXXX@XXXXX.COM ...
DataGridCommandEventHandler(dgG_DeleteCommand);
DataGridCommandEventHandler(dgG_UpdateCommand);
DataGridCommandEventHandler(dgG_CancelCommand);
e)
e)
((TextBox)(e.Item.FindControl(sDGID))).Text;
e)
of
don't