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

Question about clicking an Image in a cell...

1 Answer 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kevin
Top achievements
Rank 1
Kevin asked on 21 Feb 2014, 05:23 PM
Hello All,
     I have a grid, that in the ItemCommand event handler subroutine I handle the "RowClick" with a call to another sub...  Now here's where it gets interesting...  In the first cell/column of a row, I have an Image.  I would like it so that when the user "Clicks" the image that it fires off a server side event that I can capture and call my same sub that handles the "RowClick" event... I know that if the user clicks the "white" space around the image, that the ItemCommand event is fired for the "RowClick", but NOT for clicking inside the image itself...  The image is large enough and takes up a good bit of the cell that there is very little "white" space around it, and that it would seem to be very frustrating that nothing happens when the image itself is clicked...  
    Right now, how things stand is that it's a plain column, and a plain image in the cell.  I have NOT looked at placing an ImageButton in the cell, as I have not used that control before, nor have I looked at a GridImageColumn or a GridBinaryImageColumn yet.  the two alternative column types don't quite seem to be want I looking for, as the images are not stored in a database  or in a particular URL...  
    So...  Is there anyway to have the Image fire off some sort of server event when it is clicked or not???  That is the question of the day...

Thanks in advance!,

Kevin Orcutt
Matson Money Inc.
(513) 204-8000 x8245
(513) 204-8245 (Direct)
Kevin.Orcutt@MatsonMoney.com
www.MatsonMoney.com

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 26 Feb 2014, 11:12 AM
Hi Kevin,

You can use the following approach to achieve the requested functionality:
<asp:Image ... onclick='<%# string.Format("imageClick(\"{0}\",{1});",
    Container.OwnerTableView.ClientID, Container.ItemIndex) %>' />
JavaScript:
function imageClick(tableViewID, index) {
    var tableView = $find(tableViewID);
    var item = tableView.get_dataItems()[index];
    item.get_element().click();
}

Hope this helps. Please give it a try and let me know if it works for you.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Kevin
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or