RadGrid latest version item.enable=False does not work

4 posts, 1 answers
  1. Acadia
    Acadia avatar
    211 posts
    Member since:
    May 2005

    Posted 16 Jan 2020 Link to this post

    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!

  2. Answer
    Attila Antal
    Admin
    Attila Antal avatar
    592 posts

    Posted 21 Jan 2020 Link to this post

    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.
  3. Acadia
    Acadia avatar
    211 posts
    Member since:
    May 2005

    Posted 21 Jan 2020 in reply to Attila Antal Link to this post

    Thank you, I got it!
  4. Acadia
    Acadia avatar
    211 posts
    Member since:
    May 2005

    Posted 21 Jan 2020 in reply to Acadia Link to this post

    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

Back to Top