473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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.DataItem, "title") %></td>
</tr>
<tr>
<td><asp:datalist id="AnotherList" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "something")
%>
</ItemTemplate>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>

Then in the Code behind:

MyList.DataSource = MyDatabase.GetTitles(); // MyDatabase.GetTitles returns
a dataset
MyList.DataBind();
AnotherList.DataSource = MyDatabase.GetSomething();
AnotherList.DataBind();

I keep getting a "System.NullReferenceException: Object reference not set to
an instance of an object" error when it gets to the AnotherList.DataSource
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 1751
Okay, I get it now. I have to use a OnItemDataBound, then in the Code behind,
check the e.Item.ItemType == ListItemType.Item and AlternatingItem, then
DataList MyDataList = (DataList)e.Item.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.DataItem, "title") %></td>
</tr>
<tr>
<td><asp:datalist id="AnotherList" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "something")
%>
</ItemTemplate>
</td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>

Then in the Code behind:

MyList.DataSource = MyDatabase.GetTitles(); // MyDatabase.GetTitles returns
a dataset
MyList.DataBind();
AnotherList.DataSource = MyDatabase.GetSomething();
AnotherList.DataBind();

I keep getting a "System.NullReferenceException: Object reference not set to
an instance of an object" error when it gets to the AnotherList.DataSource
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
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...
1
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...
9
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"...
5
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>...
0
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...
0
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...
2
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">...
0
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....
4
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.