Update and Cancel events fire as Edit

Update and Cancel events fire as Edit

Post by Stev » Fri, 27 Feb 2004 15:55:51


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)
{
 
 
 

Update and Cancel events fire as Edit

Post by Stev » Fri, 27 Feb 2004 16:18:20

I just some some more articles. Could it be that it has to do with the fact
that I have to recreate the entire form on each postback?

Steve

 
 
 

Update and Cancel events fire as Edit

Post by Scott Mitc » Sat, 28 Feb 2004 06:35:40

> I just some some more articles. Could it be that it has to do with the
fact

Steve, I've not looked at your problem closely, but this would be my
assumption as to the problem. (It was my "gut feeling" when I skimmed
over your post earlier.) Remember that you'll need to not only rebind the
controls on every load, but reassign the event handlers. Too, you should
do this in the Page's Init event handler rather than in the Page_Load
event handler...

--

Scott Mitchell
XXXX@XXXXX.COM
http://www.yqcomputer.com/
http://www.yqcomputer.com/
http://www.yqcomputer.com/

* When you think ASP, think 4GuysFromRolla.com!
 
 
 

Update and Cancel events fire as Edit

Post by Stev » Sat, 28 Feb 2004 07:21:15

Thanks for looking at this.

I think I am already doing what you say. I recreate the control, rebind it
and regenerate the event handlers in the module that creates the datagrid.
I don't think I can do this in the page's init event handler because I do
not know the control at that time.

Scott. This is a critical function and I really need to get this working by
Friday. Any other suggestions?

Steve