ASP.NET Datagrid, doesn't fire events for editcmommand etc..

K

KK

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
 
A

aa7im

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....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top