1

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

Zeb-ur-Rehman
  • 1,121
  • 2
  • 21
  • 37
  • Repeater doesn't have a AutoCallback="true", remove this property and try again – Hans Derks Oct 22 '13 at 07:24
  • Yeah sorry that was my mistake. I ommit it out. But the problem was not due to autocallback.. – Zeb-ur-Rehman Oct 22 '13 at 08:55
  • I think Handles rptthumbnail.ItemCommand is enough of sub rptthumbnail_ItemCommand, no method 1 or method 2 necessary (works on my machine but I'm not a VB expert) – Hans Derks Oct 22 '13 at 09:04

0 Answers0