Repeater ItemCommand Doesn't fire

久未见 提交于 2019-12-11 09:48:47

问题


What I want
I want to fire ItemCommand event when some one click on repeater.

Issue
The ItemCommand is not fired.

Code

FrontEnd Code

<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

What i have tried so far

Method 1
I have put onItemCommand="rptthumbnail_ItemCommand" But i didn't worked.

Method 2
I have add handlar in OnInit() But i didn't worked too.

Can some please identify that what's the problem

来源:https://stackoverflow.com/questions/19510976/repeater-itemcommand-doesnt-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!