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

I want to use the edit icon instead of an edit hyperlink to show a external radwindow for editing.

2 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
troyboy
Top achievements
Rank 1
troyboy asked on 10 Nov 2010, 07:22 PM
I've got the grid edit hyperlink working but I would rather use the default edit icon. Any ideas how to do this? Here is my code:

                <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                    <FilterTemplate
                    </FilterTemplate>
                    <ItemTemplate>
                        <asp:HyperLink ID="EditLink" runat="server" Text="Edit"></asp:HyperLink>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem item = (GridDataItem)e.Item;
        HyperLink editLink = (HyperLink)e.Item.FindControl("EditLink");
        editLink.Attributes["href"] = "#";
        editLink.Attributes["onclick"] = String.Format("return ShowEditForm('{0}','{1}');", item.GetDataKeyValue("CatalogueItemId"), item.ItemIndex);
    }
}

The above works perfectly but I would really like to use the default edit icon instead of a hyperlink. Please help. Thanks

Troy

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 11 Nov 2010, 06:44 AM
Hello,
Since the Edit icon is rendered as ImageButton, you can access it from code behind as ImageButton like below

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           ImageButton editbutton = (ImageButton)item["EditCommandColumn"].Controls[0];
           editbutton.Attributes["onclick"]=//your code
       }
   }

ASPX:
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"></telerik:GridEditCommandColumn>

Thanks,
Princy.
0
troyboy
Top achievements
Rank 1
answered on 11 Nov 2010, 06:40 PM
That worked. Thanks
Tags
Grid
Asked by
troyboy
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
troyboy
Top achievements
Rank 1
Share this question
or