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

GridEditCommandColumn in ItemDatabound

3 Answers 511 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jai
Top achievements
Rank 1
Jai asked on 23 Jun 2011, 06:38 AM
Hi,

I have grid with GridEditCommandColumn and OnItemDataBound i am adding Javascript on this GridEditCommandColumn but nothing happening. Can anyone tell what i am doing wrong ? Following is my code
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" EditImageUrl="~/Images/Edit.gif"
                                        ButtonType="ImageButton">
                                    </telerik:GridEditCommandColumn>
 
if (e.Item is GridDataItem)
           {
               GridDataItem item = (GridDataItem)e.Item;
               ImageButton edit = (ImageButton)item["EditCommandColumn"].Controls[0];
               //edit.Attributes.Add("OnClick", " onContactRowSelected('" + sender + "','" + e + "');");
               edit.Attributes["onClick"] = "alert('test');return false;";
           }


One more thing my Grid has following thing as well
<ClientEvents OnCommand="radContactGrid_Command" OnRowCreated="onContactGridRowCreated"
                                    OnRowCreating="onContactGridRowCreating" OnRowSelected="onContactRowSelected" />



Thanks,
--Jai

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 24 Jun 2011, 08:49 AM
Hello Jai,

Your code seems all right, please, check out the attached sample. 

Regards,
Tsvetoslav
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Jai
Top achievements
Rank 1
answered on 24 Jun 2011, 12:50 PM
Hi Tsvetoslav,

My problem is, i have the following in my grid
<ClientEvents OnCommand="radContactGrid_Command" OnRowCreated="onContactGridRowCreated"
                                    OnRowCreating="onContactGridRowCreating" OnRowSelected="onContactRowSelected" />
And if i have that <ClientEvents> then the javascript function that i am adding on the ImageButton as attributes in code behind is not working. I mean if i comment this <ClientEvents> and then click on GridEditCommandColum, the added javascript function is working.
And my requirement is that i want both (<ClientEvents> as well as the GridEditCommandColum onclick javascript.)

Can you please tell me how to do that with RadGrid control ?
0
Tsvetoslav
Telerik team
answered on 28 Jun 2011, 08:55 AM
Hello Jai,

In this case, the code for the ItemDataBound event should become as follows:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = e.Item as GridDataItem;
 
        ((ImageButton)item["EditColumn"].Controls[0]).OnClientClick = "alert('test'); " + ((ImageButton)item["EditColumn"].Controls[0]).OnClientClick;
    }
}

Hope it helps.
 

Greetings,
Tsvetoslav
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Jai
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Jai
Top achievements
Rank 1
Share this question
or