Question : direct cast an asp button inisde a listview layout template


I am trying access a button in a list view layout template none of this will work , any suggestion?

1:
2:
3:
4:
5:
6:
7:
8:
9:
Protected Sub ListView1_LayoutCreated(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.LayoutCreated

        'Dim mybtnPrint As Button = CType(ListView1.FindControl("btnPrint1"), Button)
        'Dim myButtonPrint As Literal = DirectCast(ListView1.FindControl("btnPrint1"), Literal)
        'Dim rickButton As Button = DirectCast(ListView1.Controls(1).FindControl("btnPrint1"), Button)
        ' mybtnPrint.Attributes.Add("Onclick", "getPrint('print_area');")

        'Dim dataview As ListViewDataItem = TryCast(ListViewDataItem.DataItem, ListViewDataItem)
    End Sub

Answer : direct cast an asp button inisde a listview layout template

ok then try this

Dim mybtnPrint As System.Web.UI.Controls.Button = CType(ListView1.FindControl("btnPrint1"), System.Web.UI.Controls.Button)

or remove the System.Windows.Forms from the Import statement. it will work.
Random Solutions  
 
programming4us programming4us