views:

395

answers:

1

I'm customising the Group Headers on a Telerik RadGrid by injecting a LinkButton into it during the ItemDataBound event. The button renders perfectly, but I can't get it to hit any event handlers.

Here is the code for the button creation:

Private Sub rgWorkRequestItemCosts_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgWorkRequestItemCosts.ItemDataBound

        If TypeOf e.Item Is GridGroupHeaderItem Then

            Dim oItem As GridGroupHeaderItem = DirectCast(e.Item, GridGroupHeaderItem)
            Dim lnkAdd As New LinkButton()
            lnkAdd.ID = "lnkAdd"
            lnkAdd.CommandName = "CustomAddWorkRequestItemCost"
            lnkAdd.CommandArgument = DirectCast(oItem.DataItem, DataRowView).Row("nWorkRequestItemID").ToString()
            lnkAdd.Text = String.Format("<img style=""border:0px"" alt="""" width=""12"" src=""{0}"" /> Add new cost", ResolveUrl(String.Format("~/App_Themes/{0}/Grid/AddRecord.gif", Page.Theme)))
            lnkAdd.Style("color") = "#000000"
            lnkAdd.Style("text-decoration") = "none"
            AddHandler lnkAdd.Click, AddressOf lnkAdd_Click
            Dim tcPlaceholder As GridTableCell = DirectCast(oItem.Controls(1), GridTableCell)
            Dim litText As New LiteralControl(String.Format("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{0}", tcPlaceholder.Text))
            tcPlaceholder.Text = String.Empty
            tcPlaceholder.Controls.Add(lnkAdd)
            tcPlaceholder.Controls.Add(litText)
     End If
End Sub

This code explicitly adds a handler for the LinkButton, but that handler is never hit. I've also tried events on the RadGrid (ItemCommand, ItemEvent) but none seem to get hit.

Has anyone got any suggestions of other events to try, or ways to make this work?

Thanks!

A: 

I wasn't able to find a "nice" solution to this. In the end I did the following:

  1. Created the button in the ItemCreated event handler, setting its CommandArgument to a counter which was incremented for every group header created
  2. Again created the button in the ItemDataBound event, again settings its CommandArgument to the counter value. At this point I added a record to a dictionary object (stored in ViewState) linking the counter to the actual value of the group.
  3. Handled the click event of the button, extracting the group value from the dictionary in viewstate to complete the processing.

Ugly, but it works.

Brent