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

RadGrid - image in cell and click event

6 Answers 272 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matteo Beretta
Top achievements
Rank 1
Matteo Beretta asked on 07 May 2010, 06:15 PM

Hi, when i put a link button in a columntemplate all work fine:

<telerik:GridTemplateColumn UniqueName="colTDet" HeaderText="Numero">  
            <ItemTemplate>  
                <asp:LinkButton ID="linkDetails" runat="server" CommandName="GetDetails" Text"I  
                </asp:LinkButton>  
            </ItemTemplate>  
</telerik:GridTemplateColumn> 
if i put a imagebutton, on click the item_Command event doesn't fire

<telerik:GridTemplateColumn UniqueName="colTDet" HeaderText="Numero">  
            <ItemTemplate>  
                <asp:ImageButton ID="linkDetails" runat="server" CommandName="GetDetails" Text="Dettagli" ></asp:ImageButton>  
            </ItemTemplate>  
</telerik:GridTemplateColumn> 

How can i put a clickable image that unleash an event on grid cell?

Thank you

6 Answers, 1 is accepted

Sort by
0
Matteo Beretta
Top achievements
Rank 1
answered on 07 May 2010, 09:50 PM
Sorry still not work
0
Accepted
Veli
Telerik team
answered on 11 May 2010, 04:48 PM
Hi Matteo,

I cannot reproduce this behavior. All types of buttons (Button, LinkButton, ImageButton) should fire the ItemCommand event in RadGrid once you define CommandName for the button. Can you post some sample code we can examine?

Kind regards,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Alan Beech
Top achievements
Rank 1
answered on 25 Oct 2013, 04:11 PM
The client side row click isn't fired
0
Shinu
Top achievements
Rank 1
answered on 28 Oct 2013, 05:27 AM
Hi Alan,

I'm not clear about your requirement,if you want to have the client OnRowClick event,please set ClientSettings.Selecting.AllowRowSelect
property to true for the event to fire.

ASPX:
<ClientSettings Selecting-AllowRowSelect="true">
 <ClientEvents OnRowClick="OnRowClick" />
</ClientSettings>

JS:
<script type="text/javascript">
  function OnRowClick(sender, eventArgs) {
   alert("RowClick");
   //Your Code
   }
</script>

If this doesn't help,please elaborate on your requirements.
Thanks,
Shinu
0
Alan Beech
Top achievements
Rank 1
answered on 31 Oct 2013, 05:54 PM
When you have an image column, clicking on the image doesn't fire the client side row click, so breaks the row selecting if you use an icon for each row. I have found a workaround by using a TemplateColumn with an image instead and jQuery (making the image call the click function of the parent td) but thought it might be worth mentioning.

Maybe there could be an OnClientClick setting for the image column so that it could be set to call the same function as row click or a different function if needed.
0
Shinu
Top achievements
Rank 1
answered on 01 Nov 2013, 08:50 AM
Hi Alan,

You can wire the ItemCreated event of the Radgrid and attach the onclick client event to the image in the grid. See the code snippet below.

ASPX:
<telerik:GridImageColumn  DataImageUrlFields="CustomerID"  UniqueName="imageColumnName" HeaderText="Image Column" . . .>
</telerik:GridImageColumn>

C#:
protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridDataItem)
    {
        GridDataItem Item = (GridDataItem)e.Item;
        Image btn = (Image)Item["imageColumnName"].Controls[0];
        btn.Attributes.Add("OnClick", "imgclick('" + Item.ItemIndex + "');"); //Passing the index of the selected row
    }
}

JS:
<script type="text/javascript">
    function imgclick(index) {     
       var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();    
       masterTable.fireCommand("Select", index); //will select the row
    
</script>


Thanks,
Shinu
Tags
Grid
Asked by
Matteo Beretta
Top achievements
Rank 1
Answers by
Matteo Beretta
Top achievements
Rank 1
Veli
Telerik team
Alan Beech
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Share this question
or