473,651 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datalist within a datalist?

Is it possible in asp.net to have a datalist in the itemtemplate of another
datalist?

For example:

<asp:datalist id="MyList" runat="server">
<ItemTemplate >
<table border="0" width="300">
<tr>
<td><%# DataBinder.Eval (Container.Data Item, "title") %></td>
</tr>
<tr>
<td><asp:datali st id="AnotherList " runat="server">
<ItemTemplate >
<%# DataBinder.Eval (Container.Data Item, "something" )
%>
</ItemTemplate>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>

Then in the Code behind:

MyList.DataSour ce = MyDatabase.GetT itles(); // MyDatabase.GetT itles returns
a dataset
MyList.DataBind ();
AnotherList.Dat aSource = MyDatabase.GetS omething();
AnotherList.Dat aBind();

I keep getting a "System.NullRef erenceException : Object reference not set to
an instance of an object" error when it gets to the AnotherList.Dat aSource
line.

So is it possible to have a Datalist in another Datalist, and if so, what's
the correct way of doing it?
Nov 17 '05 #1
1 1764
Okay, I get it now. I have to use a OnItemDataBound , then in the Code behind,
check the e.Item.ItemType == ListItemType.It em and AlternatingItem , then
DataList MyDataList = (DataList)e.Ite m.FindControl(" MySomething");

I have to find the control because it's contained within the first datalist.
Makes sense.

"pete K" wrote:
Is it possible in asp.net to have a datalist in the itemtemplate of another
datalist?

For example:

<asp:datalist id="MyList" runat="server">
<ItemTemplate >
<table border="0" width="300">
<tr>
<td><%# DataBinder.Eval (Container.Data Item, "title") %></td>
</tr>
<tr>
<td><asp:datali st id="AnotherList " runat="server">
<ItemTemplate >
<%# DataBinder.Eval (Container.Data Item, "something" )
%>
</ItemTemplate>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>

Then in the Code behind:

MyList.DataSour ce = MyDatabase.GetT itles(); // MyDatabase.GetT itles returns
a dataset
MyList.DataBind ();
AnotherList.Dat aSource = MyDatabase.GetS omething();
AnotherList.Dat aBind();

I keep getting a "System.NullRef erenceException : Object reference not set to
an instance of an object" error when it gets to the AnotherList.Dat aSource
line.

So is it possible to have a Datalist in another Datalist, and if so, what's
the correct way of doing it?

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
10927
by: bill yeager | last post by:
I have a datagrid control within a datalist control. When I try and do a "Find" on the control, the object comes back with nothing and then my pgm crashes. I am 100% sure that my datagird inside my datalist has an id of "Datagrid3". dgChild comes back with "Nothing" while debugging. Here is my code in the itemdatabound event for the datalist: <code>
1
3167
by: Doug | last post by:
The html below shows DataList "DiscountList" nested within DataList "EventItemList". DiscountList contains a Label control. I'm trying to find the label, using FindControl, during EventList_ItemCreated (below the html), but it's always <undefined value> (null). Everything else works fine. Eventually I need to set the value of the label depending up the Count of the DataView "dvDiscount". For now I'll settle for just finding the damn...
9
2574
by: jjack100 | last post by:
I want to set the text value of a label that is within a datalist in the codebehind. Does this have to be done in the databound event? Simplified example: <asp:DataList id="dlItem" runat="server"> <ItemTemplate> <asp:Label ID="lblItemPrice" runat="server" /> </ItemTemplate> </asp:DataList>
5
2042
by: Petr SIMUNEK | last post by:
Is there a way to render something before the DATALIST encapsulation table gets rendered ? So that I could have Label before actual table that is rendered by DATALIST... <h1>Some Label</h1> <TABLE ID='DataList' width='100%'> *** inside datalist objects rendered *** </TABLE> Thanx to all...
0
1696
by: s.gregory | last post by:
My page layout is like this: Page >DataList (databound using ObjectDataSource1 contained in page) >>Items >>>UserControl >>>>GridView (databound using another ObjectDataSource2 contained in UserControl) So I've basically got a GridView (wrapped in a UserControl), that is nested within a DataList. Representing a fairly simple relational data
0
3936
by: Isz | last post by:
PROBLEM: This problem is related to the postback and handling events correctly. BACKGROUND: I have a datalist which acts as a tabbes list with horizontal layout. This datalist is bound to a strogly typed collection I called TabCollection which is a collevtion of items called tab. Each tab is as follows:
2
2045
by: rn5a | last post by:
I am using a DataList control to display records from a database table. The records are being rendered in a HTML table which is within the DataList....something like this: <form runat="server"> <asp:DataList ID="dlItem" AlternatingItemStyle-BackColor="lavender" ItemStyle-BackColor="pink" runat="server"> <HeaderTemplate> <table width="100%">
0
1427
by: Jim in Arizona | last post by:
Is there an easier way to make a datalist aware of line breaks within text fields? I have a text box that users can type into. If they press the enter key a few times, VB sees this as a vbCrLf. This text is inserted into a text field in an SQL server. When the data is read and presented by the datalist, the line breaks are gone. All the text is just together without paragraphing. I am able to keep the spaces if I try this approach:
4
3980
by: Peter | last post by:
I have a DataList and each item in the datalist has an imge, I want to change the datalist item image on the client side when user clicks a button. How would I do that with JavaScript, does anyone has an example of how to change a DataList item with JavaScript? Thank You Peter
0
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8694
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7294
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4280
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.