Repeater ItemCommand不触发

时间:2013-10-22 06:50:07

标签: asp.net event-handling repeater itemcommand

我想要什么
我想在点击转发器时触发ItemCommand事件。

问题
ItemCommand未被触发。

代码

FrontEnd代码

<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

的ItemDataBound

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

ItemCommand

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但是我也没有工作。

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

0 个答案:

没有答案