473,396 Members | 1,893 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,396 software developers and data experts.

nested datalist problems

I would like to create a nested datalist inside the
selecteditemtemplate of a datalist. My hope is that when a user clicks
on a link a set of child links is displayed. For example if the user
clicks men's clothing he would get a list of sub categories like pants,
shirts, shorts etc

I have put together the following and I get the original datalist fine.
When I try to get the sublist I get the following error: Object
reference not set to an instance of an object.
The offending line is

brandSubList.DataSource = Catalog.GetSubCatsInBrands(BrandID)
from the code behind listed below.
---------------------------------
HTML code looks like this:
<asp:datalist id="brandList" Runat="server">
<ItemTemplate>
<DIV class="navcells"><B>
<asp:hyperlink id="brandLink" Runat="server" NavigateUrl= '<%#
"../default.aspx?brandID=" &amp; databinder.eval(container.dataitem,
"strBrandCode") %>' text= '<%# DataBinder.Eval( Container.DataItem,
"strBrandName" ) %>' >
</asp:hyperlink></B></DIV>
</ItemTemplate>
<SelectedItemTemplate>
<asp:DataList id="brandSubList" Runat="server">
<ItemTemplate><DIV class="navcells"><B>
<asp:LinkButton id="brandsubLink" Runat="server"
CommandName="select"><%# DataBinder.Eval( Container.DataItem,
"strSubCategory" ) %>
</asp:LinkButton></B></DIV>
</ItemTemplate>
</asp:DataList>
</SelectedItemTemplate>
</asp:datalist>

---------------------------------------------------------
My code behind looks like this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim BrandID As String = Request.QueryString("brandID")

brandList.DataSource = Catalog.GetBrands()
brandList.DataBind()

If Not BrandID Is Nothing Then
Dim BrandSublist As DataList

brandSubList.DataSource =
Catalog.GetSubCatsInBrands(BrandID)
brandSubList.DataBind()

End If
--------------------------------------------------------
Data is pulled from a business objects doc like this

Public Shared Function GetBrands() As SqlDataReader
'Create connetion objedt
Dim Connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_GetBrands", Connection)
command.CommandType = CommandType.StoredProcedure

'Open the connection
Connection.Open()

'Return a SqlDatatreader
Return command.ExecuteReader(CommandBehavior.CloseConnect ion)
End Function

Public Shared Function GetSubCatsInBrands(ByVal brandID As String) As
SqlDataReader
'create the connection string
Dim connection As New SqlConnection(connectionString)
'Create and initialize the command Object
Dim command As New SqlCommand("New_getSubCatsInBrands",
connection)
command.CommandType = CommandType.StoredProcedure

'Add an input parameter and suply a valiue for it
command.Parameters.Add("@brandID", SqlDbType.NVarChar, 5)
command.Parameters("@brandID").Value = brandID
'Open the connection, exectue the command, and clost the
connection

Try
connection.Open()
command.ExecuteNonQuery()
Finally
connection.Close()
End Try

Dec 21 '05 #1
2 1485
Hello

If you check last few lines of your functions GetSubCatsInBrands and
GetBrands then you have come to know that in GetBrands after opening
connection
-------------------------------------------------------------------------------------
'Return a SqlDatatreader
Return command.ExecuteReader(CommandBehavior.CloseConnect ion)
-------------------------------------------------------------------------------------
and in function GetSubCatsInBrands after opening connection
-------------------------------------------------------------------------------------
command.ExecuteNonQuery()
-------------------------------------------------------------------------------------

So in GetSubCatsInBrands function It should be Return
command.ExecuterReader as writen in GetBrands function.

ExecuteNonQuery will not return recordset it will just execute insert,
delete or update command.

B

Dec 22 '05 #2
Hi, Thanks. I actually realized that and got the datalist working on
it's own. I can properly catch the parameter and the list will work
EXCEPT when it is nested inside another datalist.

Any advice?

Dec 22 '05 #3

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

Similar topics

4
by: V. Jenks | last post by:
What seems like a simple thing is apparently not so straightforward? I have a datalist. Inside of that datalist is an <itemtemplate> secion which contains other server controls such as a...
0
by: Marty U. | last post by:
I have two datalists nested. On the ItemDataBound Event of the first datalist I databind the second with specific info. A couple questions: 1) How can I utilize the OnItemCommand of the nested...
3
by: Derek | last post by:
I have a nested datalist with a dropdownlist. I need to capture the selectedvalue of the dropdownlist so I can update a database table. My question then is...how do I get the value from the...
0
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
3
by: Martin | last post by:
Hi, I have a very frustrating problem that I have researched for countless hours to no avail. There are many posts asking very similar things, however none usefull in my situation. I am using VS...
0
by: H5N1 | last post by:
Hi there My problem is that in when I update GridView row, which is nested into DataList control, I want to refresh also DataList in which the GridView is nested, since after update, trigger in...
0
by: Les Caudle | last post by:
I have a menu system composed of a DataList nested inside a DataList. The outer DataList has it's DataSource (composed of a DataSet with two tables linked by a CategoryPagesRelation Relation) set...
1
by: AJ | last post by:
Hi all, With the following code in mind : <asp:DataList ID="dlOne" DataKeyField="myField1" DataSource="<%# GetDataSource1()" Runat="server"> <ItemTemplate> Output Value Here! <asp:DataList...
2
by: Ole V.-M. | last post by:
Greetings, i have a UserControl, that contains a DataList. That DataList contains as items other DataLists. example: DataList A Row 1 Nested DataList 1 Row 1
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.