|
Subject:
|
Datagrid Event Problem
|
|
Posted By:
|
manoj241176
|
Post Date:
|
2/4/2004 2:14:09 AM
|
Hello Friends.. I have some prob with the following code, then prob is when i call the EditCommand of DataGrid is works fine,but when i call CancelCommand or UpdateCommand its not calling the respective events, so pls look into the code and pls let me the solution.
Thanks in advance. Manoj Singh string[] myArray= new String[] {"Verdana", "Arial", "Helvetica", "sans-serif"}; dgDetail=new System.Web.UI.WebControls.DataGrid(); dgDetail.EnableViewState=false; dgDetail.HeaderStyle.ForeColor=System.Drawing.ColorTranslator.FromHtml("#ffffff"); dgDetail.BackColor=System.Drawing.ColorTranslator.FromHtml("#000066"); dgDetail.ItemStyle.BackColor=System.Drawing.ColorTranslator.FromHtml("#d6e6f2"); dgDetail.ItemStyle.ForeColor=System.Drawing.ColorTranslator.FromHtml("#000000"); dgDetail.Font.Bold=true; dgDetail.HeaderStyle.Height=30; dgDetail.HeaderStyle.Font.Size=10; dgDetail.HeaderStyle.Font.Names=myArray; dgDetail.Font.Name="Verdana"; dgDetail.ItemStyle.Font.Size=10; dgDetail.ItemStyle.Font.Names=myArray; dgDetail.CellSpacing=2; dgDetail.CellPadding=3; dgDetail.ShowFooter=false; dgDetail.ShowHeader=true; dgDetail.BorderColor=System.Drawing.ColorTranslator.FromHtml("#FFFFFF"); dgDetail.AutoGenerateColumns=false; dgDetail.Width=800;
dgDetail.HeaderStyle.Font.Bold=true; dgDetail.ForeColor=System.Drawing.ColorTranslator.FromHtml("white"); dgDetail.BackColor=System.Drawing.ColorTranslator.FromHtml("#000050");
dgDetail.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Edit_Data); dgDetail.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Cancel_Data); dgDetail.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.Save_Data);
EditCommandColumn Edit1=new EditCommandColumn(); Edit1.ButtonType=System.Web.UI.WebControls.ButtonColumnType.PushButton; Edit1.EditText="Edit"; Edit1.CancelText="Cancel"; Edit1.UpdateText="Save"; Edit1.ItemStyle.Wrap=false; Edit1.HeaderText="Action";
BoundColumn Bcol1=new BoundColumn(); Bcol1.HeaderText="Requirement"; Bcol1.DataField="req_detail"; Bcol1.ReadOnly=true;
BoundColumn Bcol2=new BoundColumn(); Bcol2.HeaderText="Name"; Bcol2.DataField="emp_name";
dgDetail.Columns.Add(Bcol1); dgDetail.Columns.Add(Bcol2); dgDetail.Columns.Add(Edit1);
myPanel.Controls.Add(dgDetail); Bind_Grid();
private void Bind_Grid() { dgDetail.DataSource=myClass.myDataTable(sql,Conn); dgDetail.DataBind(); } protected void Cancel_Data(object sender,System.Web.UI.WebControls.DataGridCommandEventArgs e) { dgDetail.EditItemIndex=-1; Bind_Grid();
} protected void Save_Data(object sender,System.Web.UI.WebControls.DataGridCommandEventArgs e) { Response.Write(e.CommandSource.ToString()); } protected void Edit_Data(object sender,System.Web.UI.WebControls.DataGridCommandEventArgs e) { dgDetail.EditItemIndex = e.Item.ItemIndex; Bind_Grid(); }
|
|
Reply By:
|
planoie
|
Reply Date:
|
2/4/2004 9:13:10 AM
|
Where does that first block of code live? Is it in a function? Is all that code (including functions) running inline with the page?
Most likely the problem is that you are generating and populating the datagrid every time the page runs. You don't need to and can't do that if you want the grid to function properly. If you generate the grid every time the page runs, you loose the previous state of the grid. .net has no way of telling you that you hit the cancel button because as far as it's concerned the grid is fresh every time.
Peter ------------------------------------------------------ Work smarter, not harder.
|
|
Reply By:
|
manoj241176
|
Reply Date:
|
2/10/2004 12:00:56 AM
|
Hi Peter, Thanks for the help..i realised my mistake..first i have to chekc the IsPostBack method and then the viewstate of the grid has to be true. Thanks again Regards, Manoj Singh
|