动态创建的 LinkBut​​ton 不触发任何事件

发布于 2024-08-28 02:21:58 字数 1708 浏览 4 评论 0原文

我通过在 ItemDataBound 事件期间将 LinkBut​​ton 注入 Telerik RadGrid 上来自定义组标题。该按钮呈现完美,但我无法让它命中任何事件处理程序。

下面是创建按钮的代码:

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

此代码显式地为 LinkBut​​ton 添加一个处理程序,但该处理程序永远不会被命中。我也尝试过 RadGrid 上的事件(ItemCommand、ItemEvent),但似乎没有一个被击中。

有没有人对其他活动有任何建议可以尝试,或者如何使这项工作发挥作用?

谢谢!

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("              {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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乱了心跳 2024-09-04 02:21:58

我无法找到一个“好的”解决方案。最后我做了以下事情:


  1. ItemCreated 事件处理程序,设置
    其 CommandArgument 到计数器
    每增加一次
    创建的组标题
  2. 再次创建了按钮
    ItemDataBound事件,再次设置
    其 CommandArgument 到计数器
    价值。此时我添加了一个
    记录到字典对象
    (存储在 ViewState 中)链接
    与实际值相反
    团体。
  3. 处理了点击事件
    按钮,提取组值
    从 viewstate 中的字典到
    完成处理。

丑陋,但它有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文