Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
190
Event Handler not working for edit and delete button in the WebDataGrid
posted

Hi,

A webdatagrid, which is generated dynamically.
I have added an edit and delete button as a template in the grid.
I am able to invoke a javascript in the onclientclick of the buttons. But i need to add an event handler to the same buttons.
I tried to add the event handler after finding the button from the grid but it's not working.

Sample code is given below-:

GridRecordItem objGridRecordItem = (GridRecordItem)row.Items.FindItemByKey("Edit");

if (objGridRecordItem != null)
{
Button objButton = (Button)objGridRecordItem.FindControl("btnEdit");
objButton.Click += new EventHandler(btnEdit_Click);
}

Any help will be appreciated.

Thanks in advance.

  • 71886
    Suggested Answer
    Offline posted

    Hi Prasad,

    I am not sure if you want a client-side solution as I am looking at your code, but it can be achieved very easily by double-clicking on the button in the designer or use any other classic method for creating an ASP.NET server-side 'Click' event handler.

    As to the client-side solution, you can do this with the following settings:

    I am attaching a sample that demonstrates what I mean.

    WDGTemplateButtonClientClick.zip