Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Group by Category


Message #1 by "Virgil Carroll" <vcarroll@i...> on Tue, 3 Sep 2002 11:01:50 -0500
Group,

Anyone have any easier ways to group items in a datalist or repeater 
control by a certain grouping from a dataset

i.e.
Category A
	Item 1
	Item 2
Category B
	Item 1
	Item 2
	Item 3
Category C
	Item 1
	Item 2

I know how to do this the old fashion ASP way through looping, but was 
wondering if anyone knew a faster, easier way to do it in .NET.

Thanks in advance.

Tx,
Virgil Carroll
President/CEO
IStream Interactive
2013 2nd Avenue North, Suite B-4
Anoka, MN 55303
(xxx) xxx-xxxx
vcarroll@i...
www.istreaminteractive.com

Message #2 by "Dean Santillan" <webmaster@5...> on Wed, 4 Sep 2002 21:00:56 +0900
Hi,

I think your best bet would be to use a datarelation.
What I have been doing is to get the categories as a single select statement
then get the items as a another select statement.

I have some code that represents what I am trying to say, plus you could
look at the gotdotmenu source to see how they do it with repeater controls
and labels. I am using a datalisted nested in a datalist to get the children
of each category to show use this <%#
((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>' where
myrelation is the name of the datarelation.

SqlConnection cnn = new
SqlConnection(ConfigurationSettings.AppSettings["strConn"]);
				SqlDataAdapter cmd1 = new SqlDataAdapter("EXEC evosp_GetParentSections
'5','2'",cnn);
				DataSet ds = new DataSet();
				cmd1.Fill(ds,"Sections");

				SqlDataAdapter cmd2 = new SqlDataAdapter("EXEC evosp_GetAllOthers",cnn);
				cmd2.Fill(ds,"Parents");

				//Create the relation bewtween the Authors and Titles tables.

ds.Relations.Add("myrelation",ds.Tables["Sections"].Columns["SectionID"],ds.
Tables["Parents"].Columns["SectionID"]);

				//Bind the Authors table to the parent Repeater control, and call
DataBind.

				DataList1.DataSource = ds.Tables["Sections"];
				DataList1.DataBind();
				//Close the connection.
				cnn.Close();


<asp:datalist id="DataList1" runat="server" HorizontalAlign="Center"
Width="90%" RepeatColumns="2" RepeatDirection="Horizontal">
					<ItemTemplate>
						<asp:Label id="lblHead" runat="server" CssClass="text">
							<b>
								<%# DataBinder.Eval(Container.DataItem,"SectionName") %>
							</b>
						</asp:Label><br>
						<asp:repeater id=Repeater1 runat="server" datasource='<%#
((DataRowView)Container.DataItem).Row.GetChildRows("myrelation") %>'>
							<itemtemplate>
								<font class='text'>
									<asp:HyperLink id="Hyperlink2" runat="server" CssClass="text"
NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "[\"SourcePage\"]") +
"?Bubun=" + DataBinder.Eval(Container.DataItem, "[\"SectionID\"]") +
"&Peji=" + DataBinder.Eval(Container.DataItem, "[\"PageID\"]") %>'>
										<%# DataBinder.Eval(Container.DataItem, "[\"MetaName\"]")%>
									</asp:HyperLink>
								</font>
								<br>
							</itemtemplate>
						</asp:repeater>
						<BR>
					</ItemTemplate>
				</asp:datalist>


Hope that helps

Dean Santillan
MCP
webmaster@5...

-----Original Message-----
From: Virgil Carroll [mailto:vcarroll@i...]
Sent: Wednesday, September 04, 2002 1:02 AM
To: ASP+
Subject: [aspx] Group by Category


Group,

Anyone have any easier ways to group items in a datalist or repeater control
by a certain grouping from a dataset

i.e.
Category A
	Item 1
	Item 2
Category B
	Item 1
	Item 2
	Item 3
Category C
	Item 1
	Item 2

I know how to do this the old fashion ASP way through looping, but was
wondering if anyone knew a faster, easier way to do it in .NET.

Thanks in advance.

Tx,
Virgil Carroll
President/CEO
IStream Interactive
2013 2nd Avenue North, Suite B-4
Anoka, MN 55303
(xxx) xxx-xxxx
vcarroll@i...
www.istreaminteractive.com


---

ASP.NET 1.0 Namespace Reference with C#
http://www.wrox.com/acon11.asp?ISBN=1861007442

ASP.NET 1.0 Namespace Reference with VB.NET
http://www.wrox.com/acon11.asp?ISBN=1861007450

These books are a complete reference to the ASP.NET namespaces
for developers who are already familiar with using ASP.NET.
There is no trivial introductory material or useless .NET
hype and the presentation of the namespaces, in an easy-to use
alphabetical order ensures a user-friendly reference format.
We provide in-depth coverage of all the major ASP.NET classes,
giving you those real-world tips that the documentation doesn't
offer, and demonstrating complex techniques with simple
examples.

---

Message #3 by "Virgil Carroll" <vcarroll@i...> on Wed, 4 Sep 2002 12:20:17 -0500
Dean,

Thanks for the help.

Tx,
Virgil Carroll
President/CEO
IStream Interactive
2013 2nd Avenue North, Suite B-4
Anoka, MN 55303
(xxx) xxx-xxxx
vcarroll@i...
www.istreaminteractive.com


  Return to Index