Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 23rd, 2007, 11:28 PM
Friend of Wrox
Join Date: Jul 2006
Location: olathe, ks, USA.
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

Reply With Quote
  #2 (permalink)  
Old March 1st, 2007, 09:14 AM
Registered User
Join Date: Jul 2006
Location: , , .
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..

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:51 PM.

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