Solved

Find Control iniside Listview

Posted on 2011-02-25
6
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 55
Web page design problem 3 42
Call a VB.net function in Javascript 6 52
Suppress if value zero or NULL in crystal report 2 45
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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