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

How do I add an ImageButton to a column?

5 Answers 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Todd Davis
Top achievements
Rank 1
Todd Davis asked on 19 Mar 2010, 03:44 PM
I don't know why I'm having so much trouble finding info on this, but I just can't seem to find an example...

I need to add a few small ImageButtons to each row that I can use to launch an event (i.e. click on the pencil icon to edit this record, click on the little person to change the record owner, etc.).

This will be the exact same icon on every row, and will perform the same function, albeit referencing the row in question.

How do I do this?

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 19 Mar 2010, 03:55 PM
Hi Todd Davis,

The column Has a CellTemplate property .  It is a data template so you need to set the GridViewColumn.CellTemplate property to a data template containing your image .

Let me know if you need further assistance on this .

All the best,
Pavel Pavlov
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
Todd Davis
Top achievements
Rank 1
answered on 19 Mar 2010, 04:04 PM
Yes please, I could use a hand.

I figured out this much so far to add the image and fire an event:

                <grid:GridViewDataColumn>
                    <grid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="edit.png" Height="16" Width="16" MouseLeftButtonUp="Image_MouseLeftButtonUp" />
                        </DataTemplate>
                    </grid:GridViewDataColumn.CellTemplate>
                </grid:GridViewDataColumn>

So the only question for me now is, how do I associate this click with the current record (in the code behind)?

For example, let's say I have the grid bound to a collection of Person objects, and I want to know which Person I clicked the edit button on so I can display their name and address. How do I do that?
0
Todd Davis
Top achievements
Rank 1
answered on 19 Mar 2010, 04:05 PM
PS - this grid allows multiple selected items, so I can't just grab current selected item, I need to know which row was clicked.
0
Accepted
Pavel Pavlov
Telerik team
answered on 19 Mar 2010, 04:15 PM
Hi Todd ,

The image will have your person as a DataContext so checking the DataContext of the sender ( or args.originalSource)  in your event handler should let you know which is the relevant record.

If you have trouble implementing this , just paste me your event handler and I will make the changes  for you.

Best wishes,
Pavel Pavlov
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
Todd Davis
Top achievements
Rank 1
answered on 19 Mar 2010, 04:31 PM
Thanks, that worked!
Tags
GridView
Asked by
Todd Davis
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Todd Davis
Top achievements
Rank 1
Share this question
or