Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2004, 03:14 AM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Datagrid Event Problem

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.Colo rTranslator.FromHtml("#ffffff");
dgDetail.BackColor=System.Drawing.ColorTranslator. FromHtml("#000066");
dgDetail.ItemStyle.BackColor=System.Drawing.ColorT ranslator.FromHtml("#d6e6f2");
dgDetail.ItemStyle.ForeColor=System.Drawing.ColorT ranslator.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.ColorTranslato r.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.DataGridCommandEventHand ler(this.Edit_Data);
dgDetail.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.Cancel_Data);
dgDetail.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.Save_Data);


EditCommandColumn Edit1=new EditCommandColumn();
Edit1.ButtonType=System.Web.UI.WebControls.ButtonC olumnType.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.DataGridCommandEv entArgs e)
{
    dgDetail.EditItemIndex=-1;
    Bind_Grid();

}
protected void Save_Data(object sender,System.Web.UI.WebControls.DataGridCommandEv entArgs e)
{
    Response.Write(e.CommandSource.ToString());
}
protected void Edit_Data(object sender,System.Web.UI.WebControls.DataGridCommandEv entArgs e)
{
    dgDetail.EditItemIndex = e.Item.ItemIndex;
    Bind_Grid();
}
 
Old February 4th, 2004, 10:13 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
 
Old February 10th, 2004, 01:00 AM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Datagrid ItemDataBound Event Problem Grahame2003 C# 1 December 3rd, 2011 03:10 AM
Asp DataGrid Button Event jgrant General .NET 0 August 23rd, 2007 08:53 PM
Key event in datagrid shiv C# 0 August 28th, 2006 05:16 AM
DataGrid onclick event? hany ASP.NET 1.0 and 1.1 Professional 7 January 1st, 2006 05:21 AM
DataGrid click event Clive Astley Beginning VB 6 0 July 4th, 2005 12:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.