c# nested DataList

wayneph

Freshman
Joined
Jul 13, 2004
Messages
25
Location
Dallas, TX, USA
i'm having a problem getting everything right using a nested DataList. I thought I had done pretty well following an example, but apparently I'm missing something. here is the code for both the ascx and the code behind. (it's a user control)

The error it's giving me is when I add the datasource to the nested DataList.
Error: CS0117: 'object' does not contain a definition for 'Row'
Location: Line 5:<br><asp:DataList ID='linkList' DataSource='<%# Container.DataItem.Row.GetChildRows("catLink") %>'>

I've tried a few different variations on this, but it doesn't seem to be working.

linkColumn.ascx
Code:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="linkColumn.ascx.cs" Inherits="startpage.linkColumn" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:DataList id="catList" runat="server" Width="270px">
	<ItemTemplate><DIV style="DISPLAY:inline; FONT-WEIGHT: bold; FONT-SIZE: 12px; Z-INDEX: 102; LEFT: 0px; WIDTH: 270px; COLOR: white; POSITION: absolute; TOP: 0px; HEIGHT: 15px; BACKGROUND-COLOR: #000066"
	 ms_positioning="FlowLayout"><%# DataBinder.Eval(Container.DataItem, "Category") %></DIV>
		<br><asp:DataList ID='linkList' DataSource='<%# Container.DataItem.Row.GetChildRows("catLink") %>'>
			<ItemTemplate>
				<asp:HyperLink NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "LinkURL") %>'>
					<%# DataBinder.Eval(Container.DataItem, "LinkName") %>
				</asp:HyperLink>
			<br><DIV style="DISPLAY:inline; WIDTH:170px; HEIGHT:8px; font-size:6px;" ms_positioning="FlowLayout"> </DIV>
			</ItemTemplate>
		</asp:DataList>
	</ItemTemplate>
</asp:DataList>

linkColumn.ascx.cs
Code:
namespace startpage
{
	using System;
	using System.Data;
	using System.Data.SqlClient;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>
	///		Summary description for linkColumn.
	/// </summary>
	public class linkColumn : System.Web.UI.UserControl
	{
		private int colNum;
		protected System.Web.UI.WebControls.DataList catList;
		protected System.Web.UI.WebControls.DataList linkList;

		public int ColNum
		{
			set
			{
				this.colNum = value;
			}
		}


		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if (!IsPostBack)
			{
//The user is set up with access to the correct database as the default database.
				SqlConnection conn = new SqlConnection("SERVER=raynedc;UID=********;PWD=********;");
				SqlDataAdapter daCat = new SqlDataAdapter("SELECT * FROM categories WHERE CatColumn=" + this.colNum + "ORDER BY CatOrder",conn);
				SqlDataAdapter daLinks = new SqlDataAdapter("SELECT * FROM links INNER JOIN categories ON links.CatID = categories.CategoryID WHERE categories.CatColumn=" + this.colNum + " ORDER BY CategoryID, LinkOrder",conn);
				DataSet ds = new DataSet();
				
				daCat.Fill(ds.Tables.Add("categories"));
				daLinks.Fill(ds.Tables.Add("links"));

				ds.Relations.Add("catLink", ds.Tables[0].Columns[0], ds.Tables[1].Columns[1]);

				catList.DataSource = ds.Tables[0].DefaultView;
				catList.DataBind();
			}
		}
		
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
	}
}

Just for Reference here is how the User Control is being created on my aspx page.
Code:
<uc1:linkColumn id="LinkColumn1" runat="server" ColNum=1></uc1:linkColumn>
 
I found an answer...

Here is the updated ascx file if anyone ever runs into the same problem. I had to change the nested DataSource, and the way the DataBinder finds columns from the second table.

linkColumn.ascx
Code:
<%@ Import Namespace="System.Data" %>
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="linkColumn.ascx.cs" Inherits="startpage.linkColumn" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:DataList id="catList" runat="server" Width="270px">
	<ItemTemplate><DIV style="DISPLAY:inline; FONT-WEIGHT: bold; FONT-SIZE: 12px; Z-INDEX: 102; LEFT: 0px; WIDTH: 270px; COLOR: white; HEIGHT: 15px; BACKGROUND-COLOR: #000066"
	 ms_positioning="FlowLayout"><%# DataBinder.Eval(Container.DataItem, "Category") %></DIV>
		<br><asp:DataList runat=server ID='linkList'
			DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("catLink") %>'>
			<ItemTemplate>
				<asp:HyperLink runat=server NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"[\"LinkURL\"]") %>'><%# DataBinder.Eval(Container.DataItem,"[\"LinkName\"]") %></asp:HyperLink>
			</ItemTemplate>
		</asp:DataList>
		<DIV style="DISPLAY:inline; WIDTH:170px; HEIGHT:8px; font-size:6px;" ms_positioning="FlowLayout"> </DIV>	
	</ItemTemplate>
</asp:DataList>
 
Back
Top