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

7 posts, 0 answers
  1. Vineet Dhingra
    Vineet Dhingra avatar
    5 posts
    Member since:
    Sep 2009

    Posted 29 Sep 2009 Link to this post

    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>
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 02 Oct 2009 Link to this post

    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.
  3. DevCraft banner
  4. KOG
    KOG avatar
    5 posts
    Member since:
    Dec 2009

    Posted 23 Dec 2009 Link to this post

    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

  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 28 Dec 2009 Link to this post

    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.
  6. Todd Kandaris
    Todd Kandaris avatar
    1 posts
    Member since:
    Jan 2010

    Posted 15 Jan 2010 Link to this post

    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. :)
  7. KOG
    KOG avatar
    5 posts
    Member since:
    Dec 2009

    Posted 15 Jan 2010 Link to this post

    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

     

  8. Brady
    Brady avatar
    4 posts
    Member since:
    Jul 2010

    Posted 21 Jul 2010 Link to this post

    Do have sample code of this?
Back to Top
DevCraft banner