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

Obtain Data Item from RadGrid

2 Answers 186 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 06 Jun 2014, 03:58 PM
I am in the process of changing from a GridView to a RadGrid and have been experiencing a few issues.

I am attempting to pull an "Active" token from my RadGrid that displays a lot of product information. I do not have the "Active" token being displayed to the user though. It is not set to a hidden value either. The token gets pulled when the user presses the Delete button inside a GridTemplateColumn on my RadGrid.

Before with the GridView, I could use System.Web.UI.DataBinder.Eval(e.Row.DataItem, "Active") and it would return whether or not the Active token was a 1 or a 0.

I currently have the following in VB.NET:

Protected Sub rgvMyGrid_RowCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rgvMyGrid.ItemCommand
 
  If (e.CommandName = "DeleteMSDS") Then
    Dim myDelete As WinampButton = CType(e.Item.FindControl("btnDelete"), WinampButton)
    myDelete.CommandName = "DeleteMSDS"
    myDelete.CommandArgument = System.Web.UI.DataBinder.Eval(e.Item.DataItem, "MSDSID")
    If System.Web.UI.DataBinder.Eval(e.item.DataItem, "Active")
      myDelete.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to permanently delete this SDS / MSDS?');")
    End If
  End If


Before this worked like a charm, but I am having trouble. I have noticed that the System.Web.UI.DataBinder(e.Item.DataItem, "MSDSID") never returns anything. And in turn, it cannot find an instance of "Active" being used then.

2 Answers, 1 is accepted

Sort by
0
Alexander
Top achievements
Rank 1
answered on 06 Jun 2014, 04:40 PM
What I want to do is add this onclick event to my button. Depending on the value of Active, the information will be different.
0
Alexander
Top achievements
Rank 1
answered on 06 Jun 2014, 05:45 PM
What I ended up doing was creating a new function that returned a string. The onClick was set to 

<%#sendToMyDelete(DataBinder.Eval(Container.DataItem, "Active"))%>

I then had sendToMyDelete return the string for the onClick that I wanted it to be depending on the value of Active.
Tags
Grid
Asked by
Alexander
Top achievements
Rank 1
Answers by
Alexander
Top achievements
Rank 1
Share this question
or