1

我想要什么我想
在单击中继器时触发 ItemCommand 事件。

问题
ItemCommand 未触发。

代码

前端代码

<asp:Repeater ID="rptthumbnail" AutoCallback="true" runat="server" Visible="true">
         <ItemTemplate>
              <td style="height:81px;width:51px">
                   <asp:ImageButton ID="imgThumbnail" style="height:80px;width:50px" runat="server" />
              </td>
         </ItemTemplate>
 </asp:Repeater>

Page_Load

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Dim urls As List(Of String) = TryCast(Session("SliderUrls"), List(Of String))


        Dim urlsDT As DataTable = New DataTable("urls")
        Dim urlCol As DataColumn
        Dim urlrow As DataRow
        urlCol = New DataColumn()
        urlCol.DataType = System.Type.GetType("System.String")
        urlCol.ColumnName = "url"
        urlsDT.Columns.Add(urlCol)
        For value As Integer = 0 To urls.Count - 1
            urlrow = urlsDT.NewRow()
            urlrow("url") = Convert.ToString(urls(value))
            urlsDT.Rows.Add(urlrow)
        Next
        rptthumbnail.DataSource = urlsDT
        rptthumbnail.DataBind()
    End If

End Sub

项目数据绑定

Private Sub rptthumbnail_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptthumbnail.ItemDataBound
    If e.Item.ItemType = ListItemType.AlternatingItem Or e.Item.ItemType = ListItemType.Item Then
        Dim myButton As ImageButton = CType(e.Item.FindControl("imgThumbnail"), ImageButton)
        Dim drv As DataRowView = e.Item.DataItem
        myButton.CommandName = "Click"
        myButton.CommandArgument = drv.Row("url").ToString()
        myButton.ImageUrl = drv.Row("url").ToString()
    End If
End Sub

项目命令

Protected Sub rptthumbnail_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs) Handles rptthumbnail.ItemCommand
    Select Case e.CommandName
        Case Is = "Click"
            Dim abc = e.CommandArgument

        Case Else
            Exit Select
    End Select
End Sub

到目前为止我所尝试的

方法 1
我已经放了 onItemCommand="rptthumbnail_ItemCommand" 但我没有工作。

方法 2
我在 OnInit() 中添加了handlar 但我也没有工作。

有人可以确定是什么问题吗

4

0 回答 0