Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
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 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 November 30th, 2009, 11:40 AM
Join Date: Jul 2005
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.
Old November 30th, 2009, 03:52 PM
Imar's Avatar
Wrox Author
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!

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

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