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

RadGrid with Dynamically added LinkButtons loosing buttons on filter.

1 Answer 44 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Debbie
Top achievements
Rank 1
Debbie asked on 01 Jun 2016, 03:00 PM

Here is my Original Post, I had originally created a new account because I didn't realize that our team had access to an account with priority support. I apologize for the double post, but I have a feeling that this one will get noticed sooner.

Here is the text from the original post

 

Hello,
My customer has requested that we put link buttons into a specific field on a grid. The nature of the filed being that I need to have regular text followed by an unlimited number links means that I have to add my buttons dynamically. I have the text followed by links working proper upon the initial page load but something happens after the grid filter is applied. Once the grid filter is applied a post back occurs my method is still called to reformat the filed into it's final format however. Once the page loads the links are nowhere to be found and the grid cells display the text that is being converted into the buttons. Currently I am calling my logic to create the grid links on page load. I have to create the grid links in load because if I do it any later than that then my link buttons no longer function properly. Some help would be greatly appreciated. Thanks in advance below are some of my code snippets.
-Brandon

Private Sub RadGridResults_Load(sender As Object, e As EventArgs) Handles RadGridResults.Load
     For Each Item As GridItem In RadGridResults.MasterTableView.Items
          CreateGridLinks(Item)
     Next
End Sub

Private Sub CreateGridLinks(item As GridItem)
    If TypeOf item Is Telerik.Web.UI.GridDataItem Then
        Dim dataItem As Telerik.Web.UI.GridDataItem = CType(item, Telerik.Web.UI.GridDataItem)
        For Each cell As TableCell In item.Cells
            Dim Issues() As String = cell.Text.Split(";"c)
            If Issues.Length > 1 AndAlso cell.Text <> " " Then
                Dim CellText As String = Issues(0) + " "
                Dim CellId As String = ""
                Dim IssueAppealType As String = ""
                Dim IssueAppealId As String = ""
                For i As Integer = 1 To _issues.Length - 1
                    If i = 1 Then
                        cell.Controls.Add(New LiteralControl(CellText))
                    End If
                    If _issues(i).Trim.Split(":"c).Length > 1 Then
                        Dim IssueAppealButton As New LinkButton()
                        CellId = _issues(i).Trim.Replace(":", "")
  
                        Dim IssueAppealArray = _issues(i).Trim.Split(":"c)
                        IssueAppealType = IssueAppealArray(0)
                        IssueAppealId = IssueAppealArray(1)
                        IssueAppealButton.Text = IssueAppealId
                        cntrlCount += 1
                        IssueAppealButton.ID = "LinkButton" + CellId + cntrlCount.ToString
                          
                        AddHandler IssueAppealButton.Click, Sub(send, evt) HandleIssueLinkClick(IssueAppealId, IssueAppealType)
  
                        cell.Controls.Add(IssueAppealButton)
                        cell.Controls.Add(New LiteralControl(" "))
                    End If
                Next
  
            End If
        Next
    End If
End Sub

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 03 Jun 2016, 07:58 PM
Hi Debbie,

First, please note that in order to take advantage of the support you need to use the official ticket system.

However, regarding the issue that you are experiencing. Although that you approach might work initially, once you perform some operation, the Page's Load event will be too early in the page's life cycle for adding controls dynamically, because the grid will rebind after it and will recreate its structure.

The correct approach should be to create and add the controls in the OnItemCreated event and add the relevant data within the OnItemDataBound event.

Hope this helps.


Regards,
Konstantin Dikov
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Debbie
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or