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

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

1 Answer 180 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Tracy
Top achievements
Rank 1
Tracy asked on 21 Nov 2010, 08:08 AM
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.

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Nov 2010, 08:07 AM
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.
Tags
Ajax
Asked by
Tracy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or