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

How to get the value of a cell in radgrid when click on the button column

6 Answers 405 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Vineet Dhingra
Top achievements
Rank 1
Vineet Dhingra asked on 29 Sep 2009, 12:51 PM
hi,
i am having a rad grid which 4 columns and two more columns which are edit and delete which are button columns on click of edit i need to get the value of id for that particular row which is in the hidden column. here is how my grid looks like

<telerikGridView:RadGridView x:Name="radgrdFilter"  Margin="11,468,8,73" IsFilteringAllowed="True" AutoGenerateColumns="False">
            <telerikGridView:RadGridView.Columns>
                <telerikGridView:GridViewDataColumn Header="UserId" DataMemberPath="UserFilterDetailId" IsVisible="False"/>
                <telerikGridView:GridViewDataColumn Header="Filter Name" DataMemberPath="FilterName" Width="150"/>
                <telerikGridView:GridViewDataColumn Header="Filter Condition" DataMemberPath="FilterCond" Width="200"/>
                <telerikGridView:GridViewDataColumn Header="Filter Type" DataMemberPath="IsPrivate" Width="150"/>
                <telerikGridView:GridViewColumn HeaderText="Edit" Width="60">
                    <telerikGridView:GridViewColumn.CellTemplate>
                        <DataTemplate x:Name="dtTemp">
                            <Button x:Name="btnEdit" Height="20" Width="40" Click="btnEdit_Click" BorderThickness="0"><Image Source="Images/Edit.PNG" Height="20" Width="40"/></Button>
                        </DataTemplate>
                    </telerikGridView:GridViewColumn.CellTemplate>
                </telerikGridView:GridViewColumn>
                <telerikGridView:GridViewColumn HeaderText="Delete" Width="60">
                    <telerikGridView:GridViewColumn.CellTemplate>
                        <DataTemplate x:Name="dtTemp1">
                            <Button x:Name="btnDelete" Height="20" Width="40" BorderThickness="0"><Image Height="20" Width="40"/></Button>
                        </DataTemplate>
                    </telerikGridView:GridViewColumn.CellTemplate>
                </telerikGridView:GridViewColumn>
            </telerikGridView:RadGridView.Columns>
        </telerikGridView:RadGridView>

6 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Oct 2009, 06:19 AM
Hello Vineet Dhingra,

In your Button Click event handler (btnEdit_Click) you can cast sender argument to Button and get your data item using DataContext property. Since you have the entire data object you can access any object property.

All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
KOG
Top achievements
Rank 1
answered on 24 Dec 2009, 05:03 AM
Vlad,

Have the exact same need as Vineet -- to find the key for the row selected. Was not able to see the DataContext object in my code (Silverlight 3.0, RadGrid/RadGridView). The grid items appear bound okay by supplying the ItemsSource in code behind. Is the choice of using ItemsSource to bind WCF results the cause of not finding the individual data elements from a DataContext?

Tried the cast you suggested, but the values from the original source were not available.

Do not see how to access the individual grid elements. _ItemDataBound event not available for this kind of binding either.

What's the technique to access the grid elements?

Thanks.

Keefe Goldfisher

0
Vlad
Telerik team
answered on 28 Dec 2009, 07:09 AM
Hello Keefe Goldfisher,

You do not need such event (ItemDataBound) since you can access all data items using RadGridView Items property.

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Todd Kandaris
Top achievements
Rank 1
answered on 15 Jan 2010, 11:41 PM
An example of the use of this would be very helpful, or a link to an example or something.
Just telling someone to use RadGridView Items property seems a bit of a copout. 
No offense intended. :)
0
KOG
Top achievements
Rank 1
answered on 16 Jan 2010, 12:04 AM
Vlad,

Thanks for replying. We found a method to get the cell value:

<

 

telerik:RadGridView.Columns>

 

 

 

 

    <telerik:GridViewColumn Header="" Width="90" IsResizable="False" >

 

 

 

        <telerik:GridViewColumn.CellTemplate >

 

 

 

            <DataTemplate>

 

 

 

                <Button x:Name="btnEdit" Width="80" Content="Edit" Tag="{Binding ItemNo_PK}" Height="20" Click="btnEdit_Click" />

 

 

 

            </DataTemplate>

 

 

 

        </telerik:GridViewColumn.CellTemplate>

 

 

 

 

</telerik:GridViewColumn>

The use of the binding item field in the Tag attribute above did the trick. If this is a deprecated method, please let me know... and show me another way.

I don't remember seeing samples that used this technique, but I'm still getting used to Silverlight controls, so it may be lack of experience and exposure on my part.

KOG

 

0
Brady
Top achievements
Rank 1
answered on 22 Jul 2010, 02:35 AM
Do have sample code of this?
Tags
Calendar
Asked by
Vineet Dhingra
Top achievements
Rank 1
Answers by
Vlad
Telerik team
KOG
Top achievements
Rank 1
Todd Kandaris
Top achievements
Rank 1
Brady
Top achievements
Rank 1
Share this question
or