Reference the selected row in code behind using vb or c#

2 posts, 1 answers
  1. Tracy
    Tracy avatar
    123 posts
    Member since:
    Nov 2010

    Posted 21 Nov 2010 Link to this post

    Hi,

    I just downloaded the trial version of the Telerik Controls and am trying to convert an existing gridview to a Rad Gridview.  In my old grid I had a button in one of the columns that when clicked it would open a modal popup window.

    Here is the code I used for the onclick event of the button in my original grid, but it doesn't work for the rad grid.  I get the error message
    Unable to cast object of type 'Telerik.Web.UI.GridDataItem' to type 'System.Web.UI.WebControls.GridViewRow'.

    Public Sub ibtShowWarnings_OnClick(ByVal sender As Object, ByVal e As EventArgs)

            Dim ibtWarnings As ImageButton = DirectCast(sender, ImageButton)
            Dim SelectedRow As GridViewRow = DirectCast(ibtWarnings.NamingContainer, GridViewRow)
            Dim hdfMessage As HiddenField = DirectCast(SelectedRow.FindControl("hdfWarningMessage"), HiddenField)
            Dim lblSource As Label = DirectCast(SelectedRow.FindControl("lblSourceName"), Label)
            Dim aryMessages As New ArrayList
            Me.lblMessageHeading.Text = "Warnings For Source " & lblSource.Text
            aryMessages.AddRange(Split(hdfMessage.Value.ToString, "~"))
            Me.bltMessages.DataSource = aryMessages
            Me.bltMessages.DataBind()
            Me.pnlPage.BackImageUrl = "~/App_Themes/Images/Gradient Fills/Blue/Gradient Med Blue Beige 1000 x 400.png"
            Me.mpeWarningErrorMessages.Show()

        End Sub


    I understand that it doesn't consider a gridview row as a rad grid row, but how do you declare a rad grid row?

    I found one demo in the samples that does something similar but it used java script. 
    Is there a way to get the row of the button that was clicked in the code behind using vb or c?

    Thanks for you help.

  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 22 Nov 2010 Link to this post

    Hello Tracy,


    You need to convert row to type GridDataItem instead of GridViewRow when using RadGrid.

    Another option is setting the CommandName for the button and in the grid's  ItemCommand event, check for the CommandName and execute the server code.

    And the demo shows similar scenario of showing modal RadWindow on clicking button in grid row. Check this also and see whether it is suitable for your need.
    Edit Dialog for RadGrid


    -Shinu.
Back to Top