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

RadGrid latest version item.enable=False does not work

3 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Acadia
Top achievements
Rank 1
Iron
Acadia asked on 16 Jan 2020, 01:56 PM

Hello,

I'm really hoping somebody can shed light onto why code that was working in an earlier version of RadGrid no longer works after updating to the latest version of Grid.  This code was working fine before the update.  Now, although it sets the Enables property as expected (and I see this in the console) the change is not rendered on the grid.  Am I doing something wrong?  Or did this functionality actually get broken?  It was a very easy way to disable a row.  I understand there are other ways to do this, but they require more code.  Seems silly that this would be taken away and I'm hoping I am wrong.  Thanks!

 

Public Sub rgbt_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgbt.ItemDataBound

 Dim item As GridDataItem = CType(e.Item, GridDataItem)
                Dim lblEmpMsg As Label = CType(e.Item.FindControl("lblEmpMsg"), Label)
                Dim empMsgVal As String = lblEmpMsg.Text

                If (empMsgVal = "" Or IsDBNull(empMsgVal)) Then
                    item.Enabled = True
                Else
                    item.Enabled = False
                End If

End sub

 

Thanks!

3 Answers, 1 is accepted

Sort by
0
Accepted
Attila Antal
Telerik team
answered on 21 Jan 2020, 08:23 AM

Hi Acadia,

It would be very helpful if you could provide us a little more information about current configuration, such as the Grid markup and code behind code related to it.

For instance, I would need to understand what is in the markup the VB code is trying to access. Based on the code I am assuming there is a Template Column which you would like to access, similar to this example:

<telerik:GridTemplateColumn>
    <ItemTemplate>
        <asp:Label ID="lblEmpMsg" runat="server"></asp:Label>
    </ItemTemplate>
</telerik:GridTemplateColumn>

 

Please note that the Grid has multiple types of items. HeaderItem, FooterItem, FilterItem, DataItem, etc... and the ItemDataBound applies for all, see Accessing rows.

You will need to apply a condition to the VB code that will check and only run the code for Dataitems, or otherwise, it may cause unexpected behavior.

Public Sub rgbt_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgbt.ItemDataBound
    'first you will need to check whether the item is a type of GridDataItem
    ' it could also be an Edit Form when the Grid edits the row..
    If TypeOf e.Item Is GridDataItem Then
        'cast the item
        Dim item As GridDataItem = CType(e.Item, GridDataItem)

        Dim lblEmpMsg As Label = CType(e.Item.FindControl("lblEmpMsg"), Label)

        Dim empMsgVal As String = lblEmpMsg.Text

        If (empMsgVal = "" Or IsDBNull(empMsgVal)) Then
            item.Enabled = True
        Else
            item.Enabled = False
        End If
    End If

End Sub

 

In addition to the markup I would also need to know which version of the Telerik controls have you upgraded from? That would help me search for changes in between.

 

Kind regards,
Attila Antal
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Acadia
Top achievements
Rank 1
Iron
answered on 21 Jan 2020, 11:40 AM
Thank you, I got it!
0
Acadia
Top achievements
Rank 1
Iron
answered on 21 Jan 2020, 11:48 AM

Just for other users, I ended up using this method in the ItemDataBound of the grid:

 

If (TypeOf e.Item Is GridDataItem) Then

  If (whatever) then

       e.Item.SelectableMode = GridItemSelectableMode.None

  End If

End if

Tags
Grid
Asked by
Acadia
Top achievements
Rank 1
Iron
Answers by
Attila Antal
Telerik team
Acadia
Top achievements
Rank 1
Iron
Share this question
or