Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Find Control iniside Listview

Posted on 2011-02-25
6
Medium Priority
?
332 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 400 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 1600 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Integration Management Part 2
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

783 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