This is a migrated thread and some comments may be shown as answers.

[Solved] Click event of GridButtonColumn at runtime

1 Answer 351 Views
Grid
This is a migrated thread and some comments may be shown as answers.
VS
Top achievements
Rank 1
VS asked on 22 Apr 2009, 07:03 AM
Hi,

I am dynamically generating the radgrid at runtime (coz number of columsn will be known only at runtime). I am adding a GridButtonColumn for each column as below (where * is the GridButtonColumn..which will be an ImageButton, ValueA1, ValueB1, etc are Textbox in ItemTemplate)

Name                                        A                                            B

Test1                                    valueA1    *                               valueB1    *
Test2                                    valueA2     *                               valueB2   *
Test3                                    valueA3     *                               valueB3   *
                    Bulk Update      Textbox1  *                               Textbox2 *

The code for it is as below,

btnColOk = new GridButtonColumn();

 

btnColOk.ButtonType =

GridButtonColumnType.ImageButton;

 

rgTest.MasterTableView.Columns.Add(btnColOk);

btnColOk.ImageUrl =

@"~\Images\tick.png";

 

btnColOk.CommandName =

"btnColOk_Click";

Now in the ItemCommand Event, the code is as below,

 

protected

void rgTest_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

if (e.CommandName == "btnColOk_Click")

 

{

 

GridDataItem dataItem = (GridDataItem)e.Item;

 

 

ImageButton btn1 = (ImageButton)dataItem["btnColOk"].Controls[0];

 

btn1.Click +=

new ImageClickEventHandler(btn1_Click);

 

}

}

Now when i click on any ImageButtons, am getting an error as
"An error has occurred because a control with id 'rgTest$ctl00$ctl04$ctl00' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error. "

But am not able to specify an id for 'btnColOk' GridButtonColumn.
Can anyone please help me in this?

Thanks

Sujith

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 24 Apr 2009, 04:06 PM
Hello Sujith,

The ItemCommand event is posback event and it is a bit late stage in the page lifecycle to assign OnClick handler for your image button. The proper place to do that is the ItemCreated event handler of the grid as explained in this help topic.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
VS
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or