ITemplate和linkbutton点击事件

时间:2010-11-26 21:53:52

标签: asp.net

在我的用户控件中,我有gridview,这个网格是使用Itemplate以编程方式创建的。在InstantiateIn方法中,我有这段代码。

Select Case _templateType
      Case ListItemType.Header
          Dim linkButton As New LinkButton
          linkButton.Text = "Delete"
          linkButton.CommandName = "Click"
          linkButton.CommandArgument = Me._columnID

          container.Controls.Add(linkButton)

我想将Click事件连接到此LinkBut​​ton,并在代码后面使用此事件。 这是GridViewTemplate的构造函数如何实现ITemplate

Public Sub New(ByVal type As ListItemType, ByVal colname As String, Optional ByVal infoType As String = "")
    'Stores the template type.
    _templateType = type
    'Stores the column name.
    _columnName = colname

    _infoType = infoType

    _columnID = columID

  End Sub

我从用户控件那里得到了这个电话:

bfield.ItemTemplate = New GridViewTemplate(ListItemType.Item, dt.Columns(col).ColumnName, "label")

在哪里

Dim bfield As TemplateField = New TemplateField()

2 个答案:

答案 0 :(得分:0)

AddHandler linkbutton.Click, AddressOf X 'X being the method that handles the click event.

答案 1 :(得分:0)

AddHandler linkButton.Click, AddressOf linkButton_Click

Sub linkButton_Click(ByVal sender As System.Object, ByVal e As EventArgs)
   ' here is your click handler
End Sub