Groups | Blog | Home
all groups > asp.net webcontrols > november 2004 >

asp.net webcontrols : ASP.NET Datagrid, doesn't fire events for editcmommand etc..



KK
11/29/2004 9:31:06 AM

Hi guys

I am using the ASP.NET datagrid webcontrol.
It has an <asp:editcommandcolumn> with a
pushbutton type. The problem is when I click
the button it does not fire the;
private void dgQuestions_EditCommand(object source,

DataGridCommandEventArgs e) event.

To my knowledge for this there can be couple of
issues.

1) On page load if I miss a
if (!Page.IsPostBack)
}
{

then, everytime the datagrid will get loaded and
event will not get fired. But in my case I
check for postbacks.

2) If vent handler is not registered. I have attached it
as below in my code behind file;
DataGridCommandEventHandler(this.dgQuestions_EditCommand);
this.btndelete.Click += new System.EventHandler(this.btndelete_Click);

However, I have not specified,
<asp:DataGrid blah blah blah OnEditCommand="MyDataGrid_Edit" />
I attached the event using the properties window of the control.

Funny thing is even If I specify the OnEditCommand="MyDataGrid_Edit"
etc... it stil doesn't work.

What happense is when I click the button, it posts but datagrid
becomes empty, when it should show textfields for each column
for that particulr row.

It cannot be a caching problem because when I change
anything else on the same page, those changes does
gets effected.

If I debug, and press the edit button on the grid, it
go to load_page, skips the binding because of
the (!Page.IsPostBack), but then doesn't go to
the EVENT CODE!!!

Help!

rgds
KK

aa7im
11/29/2004 10:17:45 AM
The OnEditCommand needs to be registered for the DataGrid in the Init()
section of the code-behind or in the properties for the Datagrid on the
ASPX page. Regsitering a click event on the actual button will not
make the OnEditCommand event to fire...

Once you get the OnEditCommand to fire you need to set the editmode of
the grid and then rebind your data....
AddThis Social Bookmark Button