Solved

Find Control iniside Listview

Posted on 2011-02-25
6
309 Views
Last Modified: 2012-05-11
I am trying to access a printbutton inside my listview control on a 3.5 asp form.

What I am trying to accomplish is to call a java script which validates the checkboxes on the lsitview.

Where should I been creating this sub procedure?

How do i access the print button?


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here

Dim myButtonPrintOut1 As Button = CType(ListView1.FindControl("printButton1"), Button)
 myButtonPrintOut1.Attributes.Add("onclick", "return checkboxChecked()")

 End Sub

Open in new window

0
Comment
Question by:TonyReba
  • 3
  • 2
6 Comments
 
LVL 9

Assisted Solution

by:rawinnlnx9
rawinnlnx9 earned 100 total points
ID: 34984415
0
 
LVL 9

Author Comment

by:TonyReba
ID: 34984459
well not really I am trying to fire an event on mybuttonprint click which will call a javascript , but my code doesnt seem to find it
0
 
LVL 4

Expert Comment

by:Tuyau2poil
ID: 34986286
you must add  onitemdatabound="ListView1_ItemDataBound" to listview1 control in aspx section and put that code in your vb section :

Protected Sub ListView1_ItemDataBound(sender As Object, e As ListViewItemEventArgs)
      If e.Item.ItemType = ListViewItemType.DataItem Then
            Dim myButtonPrintOut1 As Button = CType(e.item.FindControl("printButton1"), Button)            
            myButtonPrintOut1.Attributes.Add("onclick", "return checkboxChecked()")
      end if
End Sub
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 9

Author Comment

by:TonyReba
ID: 34997252
Hi thanks for your advise , unfortunately when I press print the javascript is not being called,,,?
Protected Sub ListView1_ItemDataBound(ByVal sender As Object, ByVal e As ListViewItemEventArgs)
        If e.Item.ItemType = ListViewItemType.DataItem Then
            Dim myButtonPrintOut1 As Button = CType(e.item.FindControl("printButton1"), Button)
            myButtonPrintOut1.Attributes.Add("onClientClick", "checkboxChecked()")
            myButtonPrintOut1.OnClientClick = "javascript:return confirm('You wish to do this?');"

        End If
    End Sub

Open in new window

0
 
LVL 4

Accepted Solution

by:
Tuyau2poil earned 400 total points
ID: 34998518
can you verifie aspx listview control is similar to this in aspx code ?:

<asp:ListView ID="ListView1" runat="server"
            OnItemDataBound="ListView1_ItemDataBound" DataKeyNames="something"
            DataSourceID="SqldatasourceXXX" >
            <ItemTemplate>              
               <tr style="background-color: #FFFBD6;color: #333333;">
                    <td>
                        <asp:Label ID="myID1" runat="server" Text='<%# Eval("something") %>' />
                    </td>
                    <td>
                        <asp:Label ID="myID2" runat="server" Text='<%# Eval("something_else") %>' />
                    </td>
                     <td>
                        <asp:button ID="printbutton1" runat="server" Text='PRINT' />                    </td>
                </tr>
            </ItemTemplate>
           
ensure that "ListView1_ItemDataBound" is fired by debugging and putting break-points in codebehind.
Alan

0
 
LVL 9

Author Closing Comment

by:TonyReba
ID: 35000371
got it, thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now