Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 23rd, 2007, 11:28 PM
Friend of Wrox
Join Date: Jul 2006
Posts: 238
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via MSN to rsearing
Default How to get to controls inside DataList?

I have a datalist that has four labels. The text property of these labels are bound to personalized functions (see below). How can I get access to the controls inside the DataList (the labels) so that I can add them to another control to render to Excel?

My DataList:

<asp:DataList ID="DataList2" runat="server" DataSourceID="KnightsDataSource1">
                        <div style="width:60px; float:left"><asp:Label ID="Label5" runat="server" Text="" Font-Bold="true" Font-Underline="true" ></asp:Label></div>
                        <div style ="width:60px; float:left"><asp:Label ID="Label7" runat="server" Text="" Font-Bold="true" Font-Underline="true" ></asp:Label></div>
                        <div style ="width:40px; float:left"><asp:Label ID="Label8" runat="server" Text="Hrs" Font-Bold="true" Font-Underline="true" ></asp:Label></div>
                        <div style="width:40px; float:left"><asp:Label ID="Label9" runat="server" Text="Mins" Font-Bold="true" Font-Underline="true" ></asp:Label></div>
                        <div style="clear:left; float:left; width:60px"><asp:Label ID="Label3" runat="server" Text='<%# Bind("fname") %>'></asp:Label></div>
                        <div style="float:left; width:60px"><asp:Label ID="Label7" runat="server" Text='<%# Bind("lname") %>' ></asp:Label></div>
                        <div style="float:left; width:40px"><asp:Label ID="Label6" runat="server" Text='<%# EventStruct.CalculateHours(Eval("total")) %>'></asp:Label></div>
                        <div style="float:left; width:40px"><asp:Label ID="Label1" runat="server" Text='<%# EventStruct.CalculateMinutes(Eval("total")) %>'></asp:Label> </div>


Public Shared Function CalculateHours(ByVal total As Object) As Integer
        Dim returnInt As Integer = 0
        If total IsNot DBNull.Value Then
            returnInt = (total / 60) - 0.5
        End If
        Return returnInt
    End Function

    Public Shared Function CalculateMinutes(ByVal total As Object) As Integer
        Dim returnInt As Integer = 0
        If total IsNot DBNull.Value Then
            returnInt = total Mod 60
        End If
        Return returnInt
    End Function

Old March 1st, 2007, 09:14 AM
Registered User
Join Date: Jul 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts

Im still new to ASP.NET but basically as far as i know you have to use the findcontrol on the datalist so something like:

Dim lbl as new label = datalist2.findcontrol("label5")
Dim lbltext as string = lbl.text

Or something along those lines..

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to tie to nested GridView inside DataList rsearing ASP.NET 2.0 Basics 6 June 18th, 2011 06:35 AM
Datalist inside datalist amit.jagtap ASP.NET 2.0 Professional 1 September 4th, 2007 05:03 AM
Validation controls in datalist anujrathi ASP.NET 1.0 and 1.1 Professional 4 July 26th, 2006 03:32 PM
Problem with datagrid inside a datalist hoeknu ASP.NET 1.0 and 1.1 Professional 3 April 4th, 2006 10:45 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.