Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 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 November 30th, 2009, 11:40 AM
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Question Can I Nest a DataList Within a LoginView's RoleGroup?

I need to know if you can nest a datalist within a LoginView's RoleGroup. I have two separate datalists, and I want to show one for admin users, and another for dept-specific users using ASP.NET Membership. Here is what I have:

<asp:LoginView ID="LoginView1" runat="server">
            Below is a list of jobs:
            <asp:RoleGroup Roles="Public Works">
                    <!-- DEPT-SPECIFIC DATALIST GOES HERE -->
            <asp:DataList ID="dlJobs_depts" runat="server">
                <ItemTemplate><asp:Label ID="lblJobTitle" runat="server" /></ItemTemplate>
            <asp:RoleGroup Roles="Power Admin">
                    <!-- ADMIN DATALIST GOES HERE -->
            <asp:DataList ID="dlJobs_admin" runat="server">
                <ItemTemplate><asp:Label ID="lblJobTitle" runat="server" /></ItemTemplate>
And this is the resulting error: Compiler Error Message: BC30451: Name 'dlJobs_admin' is not declared.

So my questions are:

* Is there a way to do this?
* If not, what would be an alternative?
* If so, what am I doing wrong?

Thanks for any and all help.
  #2 (permalink)  
Old November 30th, 2009, 03:52 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts

Since you can now have (or in fact, you do already have) multiple controls with the same name in different scopes, you can no longer access them directly in your code. Instead, you need to use FindControl on the LoginView to "find" your DataList control:

DataList myList = LoginView1.FindControl("dlJobs_admin") as DataList;
if (myList != null)
// Use myList here

Dim myList As DataList = TryCast(LoginView1.FindControl("dlJobs_admin"), DataList)
If myList IsNot Nothing Then
' Use myList here
End If

Untested, written in this post's message window but it should do the trick.



Imar Spaanjaars
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

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
DataList pbyrum ASP.NET 2.0 Basics 2 December 3rd, 2009 04:01 PM
HELP: I need to Nest Controls in a TreeNode ctt ASP.NET 2.0 Professional 0 January 4th, 2008 06:02 PM
Nest elements carlosaml XSLT 5 October 16th, 2007 01:53 AM
Datalist inside datalist amit.jagtap ASP.NET 2.0 Professional 1 September 4th, 2007 05:03 AM
nest radio button lists and postbacks lisabb ASP.NET 2.0 Basics 0 June 6th, 2007 11:41 AM

All times are GMT -4. The time now is 01:01 AM.

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