2 column datalist with child views
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngescalate' list.


Morkai Kurst

I've asked this question on AspNgFreeforall and AspNgData
approximately 6 times over the last few months, since I first started
working with Beta1. Nobody has ever responded on any occasion and I'm
beginning to wonder if its simply impossible or so simple people don't
think it's worth answering :)

I'm creating dynamic pages to show the types and ranges of various
water heaters we sell by manufacturer. I have the by manufacturer bit
sorted nicely. Its the second bit I'm stuck on.

For this part I'm using 2 tables - Table 1 has product types eg
Handwash Units and OverSink Units. Table 2 has the manufacturer's
ranges of each type. For instance 1 manufacturer has 2 different
OverSink units. Or there are multiple versions of the product.

My tables are of the format:

Product Types:
mfgId    |typeId    | typeHeading
1    | 1        | Handwash Units
1    | 2        | OverSink Units

Ranges:
mfgId    |typeId    |rangeId    |rangeHeading
1    | 1        | 1        | Handy Mk1
1    | 1        | 2        | Handy Mk2
1    | 2        | 3        | Express
1    | 2        | 4        | Aquarius

I would like to display something like this:

Handwash Units    Undersink Units
Handy Mk1     Aquapoint
Handy Mk2

OverSink Units    Cylinders
Express         MegaFlo
Aquarius         MegaLife

etc etc. This can go on for 10+ product types and numerous ranges. So
ideally I would like to get the product types into 2 columns as above.
I have a relational dataset and a datalist that had child views. Which
is
working nicely except for the fact I can't get the multiple columns
working with the child views. I don't get any errors, it just gets
ignored completely. I can get the childview into 2 columns but not the
main heading. I've taken the blockquotes out, the span style, anything
that seemed superfluous and the only thing that made a difference was
if I took the child view out. Then it would go into 2 columns.

I need to get this into 2 columns otherwise the page is going to be
far too long on some manufacturers pages and people are going to
complain about having to scroll. Is this simply not possible with a
datalist using childviews? If not what can I use instead?

Thankyou for listening.

Morkai

This is my code:

<%@ Page Language="vb" debug="true" %>
<%@ Register TagPrefix="EWH" TagName="Header" Src="header.ascx" %>
<%@ Register TagPrefix="EWH" TagName="Menu" Src="menu.ascx" %>
<%@ Register TagPrefix="EWH" TagName="mfgPagesMfg"
Src="mfgPagesMfg.ascx" %>

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>

<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

Dim mfgCode as string
mfgCode = request.querystring("mfgId")
If (mfgCode = "") Then
mfgCode = 1
end if

Dim myDataSet As New DataSet
Dim myConn As OdbcConnection
Dim myDataAdapater As OdbcdataAdapter
Dim rel

myConn = New OdbcConnection("DSN=ewhi")
myConn.Open()

myDataAdapater = New OdbcdataAdapter("SELECT mfgId, typeId,
typeHeading
FROM conType
WHERE mfgId =" & mfgCode, myConn)
myDataAdapater.Fill(myDataSet, "conType")

myDataAdapater = New OdbcdataAdapter("SELECT mfgId, typeId, rangeId,
rangeHeading
FROM conRange
WHERE mfgId =" & mfgCode, myConn)
myDataAdapater.Fill(myDataSet, "conRange")

rel = new dataRelation
("TypeRange",myDataSet.Tables("conType").Columns("typeID"),myDataSet.T
ables("conRange").Columns("typeID"))
myDataSet.Relations.Add(rel)
Range.DataSource=myDataSet.Tables("conType").DefaultView
Range.DataBind()

End Sub

</script>

<html>
<head>

<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body leftmargin="0" topmargin="0" bgcolor="#FFFFFF">
<table width="95%" border="0" cellspacing="0" cellpadding="0"
align="center">
<tr>
<td>

<asp:DataList id="Range" cellpadding="3" cellspacing="0" width="95%"
MaintainState="false"
runat="server"
RepeatLayout="Flow"
RepeatDirection="horizontal"
RepeatColumns="2"
>

<ItemTemplate>

<span style="font: 14pt arial; color:#0000CC; font-weight: bold;"
runat="server">
<%# Container.DataItem("TypeHeading")%>
</span>

<blockquote>

<asp:DataList id="Type" runat="server"
Datasource='<%#
CType(Container.DataItem,DataRowView).CreateChildView("TypeRange") %>'
>

<ItemTemplate>
    <asp:HyperLink
     CssClass="MenuUnselectedBody"
     id=HyperLink2
     Text='<%# Container.DataItem("RangeHeading") %>'
     NavigateUrl='<%# "mfgProducts.aspx?rangeId=" &
Container.DataItem("rangeId")%>'
     runat="server"
    />
</ItemTemplate>
</asp:DataList>
</blockquote>
</ItemTemplate>
</asp:DataList>

</td>
</tr>
</table>

Reply to this message...
 
    
Susan Warren
Morkai --

So you've got a DataSet with a couple of relations in it that render the
child views you are after. That part seems correct. I think your
super close to the solution -- have you tried a DataGrid with 2
TemplateColumns as the parent control (not DataList)? Like this
(setting child view to be the datasource of the nested datalist):

    DataGrid---------------------
     col1 | col2 =20
    -----------------------------
     datalist1 | datalist2
     (childview1) | (childview2)        =09
    -----------------------------

hth,
Susan

-----Original Message-----
From: Morkai Kurst [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 05, 2001 2:36 AM
To: aspngescalate
Subject: [aspngescalate] 2 column datalist with child views

I've asked this question on AspNgFreeforall and AspNgData
approximately 6 times over the last few months, since I first started
working with Beta1. Nobody has ever responded on any occasion and I'm
beginning to wonder if its simply impossible or so simple people don't
think it's worth answering :)

I'm creating dynamic pages to show the types and ranges of various
water heaters we sell by manufacturer. I have the by manufacturer bit
sorted nicely. Its the second bit I'm stuck on.

For this part I'm using 2 tables - Table 1 has product types eg
Handwash Units and OverSink Units. Table 2 has the manufacturer's
ranges of each type. For instance 1 manufacturer has 2 different
OverSink units. Or there are multiple versions of the product.

My tables are of the format:

Product Types:
mfgId    |typeId    | typeHeading
1    | 1        | Handwash Units
1    | 2        | OverSink Units

Ranges:
mfgId    |typeId    |rangeId    |rangeHeading
1    | 1        | 1        | Handy Mk1
1    | 1        | 2        | Handy Mk2
1    | 2        | 3        | Express
1    | 2        | 4        | Aquarius

I would like to display something like this:

Handwash Units    Undersink Units
Handy Mk1     Aquapoint
Handy Mk2

OverSink Units    Cylinders
Express         MegaFlo
Aquarius         MegaLife

etc etc. This can go on for 10+ product types and numerous ranges. So
ideally I would like to get the product types into 2 columns as above.
I have a relational dataset and a datalist that had child views. Which
is
working nicely except for the fact I can't get the multiple columns
working with the child views. I don't get any errors, it just gets
ignored completely. I can get the childview into 2 columns but not the
main heading. I've taken the blockquotes out, the span style, anything
that seemed superfluous and the only thing that made a difference was
if I took the child view out. Then it would go into 2 columns.

I need to get this into 2 columns otherwise the page is going to be
far too long on some manufacturers pages and people are going to
complain about having to scroll. Is this simply not possible with a
datalist using childviews? If not what can I use instead?

Thankyou for listening.

Morkai

This is my code:

<%@ Page Language=3D"vb" debug=3D"true" %>
<%@ Register TagPrefix=3D"EWH" TagName=3D"Header" Src=3D"header.ascx" %>
<%@ Register TagPrefix=3D"EWH" TagName=3D"Menu" Src=3D"menu.ascx" %>
<%@ Register TagPrefix=3D"EWH" TagName=3D"mfgPagesMfg"
Src=3D"mfgPagesMfg.ascx" %>

<%@ Import Namespace=3D"System.Data" %>
<%@ Import Namespace=3D"System.Data.Odbc" %>

<script runat=3D"server">

Sub Page_Load(sender As Object, e As EventArgs)

Dim mfgCode as string
mfgCode =3D request.querystring("mfgId")
If (mfgCode =3D "") Then
mfgCode =3D 1
end if

Dim myDataSet As New DataSet
Dim myConn As OdbcConnection
Dim myDataAdapater As OdbcdataAdapter
Dim rel

myConn =3D New OdbcConnection("DSN=3Dewhi")
myConn.Open()

myDataAdapater =3D New OdbcdataAdapter("SELECT mfgId, typeId,
typeHeading
FROM conType
WHERE mfgId =3D" & mfgCode, myConn)
myDataAdapater.Fill(myDataSet, "conType")

myDataAdapater =3D New OdbcdataAdapter("SELECT mfgId, typeId, rangeId,
rangeHeading
FROM conRange
WHERE mfgId =3D" & mfgCode, myConn)
myDataAdapater.Fill(myDataSet, "conRange")

rel =3D new dataRelation
("TypeRange",myDataSet.Tables("conType").Columns("typeID"),myDataSet.T
ables("conRange").Columns("typeID"))
myDataSet.Relations.Add(rel)
Range.DataSource=3DmyDataSet.Tables("conType").DefaultView
Range.DataBind()

End Sub

</script>

<html>
<head>

<link rel=3D"stylesheet" type=3D"text/css" href=3D"style.css">
</head>
<body leftmargin=3D"0" topmargin=3D"0" bgcolor=3D"#FFFFFF">
<table width=3D"95%" border=3D"0" cellspacing=3D"0" cellpadding=3D"0"
align=3D"center">
<tr>
<td>

<asp:DataList id=3D"Range" cellpadding=3D"3" cellspacing=3D"0" =
width=3D"95%"
MaintainState=3D"false"
runat=3D"server"
RepeatLayout=3D"Flow"
RepeatDirection=3D"horizontal"
RepeatColumns=3D"2"
>

<ItemTemplate>

<span style=3D"font: 14pt arial; color:#0000CC; font-weight: bold;"
runat=3D"server">
<%# Container.DataItem("TypeHeading")%>
</span>

<blockquote>

<asp:DataList id=3D"Type" runat=3D"server"
Datasource=3D'<%#
CType(Container.DataItem,DataRowView).CreateChildView("TypeRange") %>'
>

<ItemTemplate>
    <asp:HyperLink
     CssClass=3D"MenuUnselectedBody"
     id=3DHyperLink2
     Text=3D'<%# Container.DataItem("RangeHeading") %>'
     NavigateUrl=3D'<%# "mfgProducts.aspx?rangeId=3D" &
Container.DataItem("rangeId")%>'
     runat=3D"server"
    />
</ItemTemplate>
</asp:DataList>
</blockquote>
</ItemTemplate>
</asp:DataList>

</td>
</tr>
</table>

| [aspngescalate] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngescalate.asp =3D JOIN/QUIT

Reply to this message...
 
    
Morkai Kurst

Thanks Susan, apologies for the delay i've been moving house all
weekend (ugg)

I think i can see where your thinking is going. What i can't see is
how to make a datalist for each column. I have no idea how many
product type headings i'm going to get out of the database, it could
be 2 or 14 or more. Do I need to look into counting the records
returned in the dataset, assigning the first half to one datalist and
the second half to another?

I can cope with counting the records, but I'm not sure how to take the
result and manipulate it into 2 datalists.

Thanks for your help

Morkai

[Original message clipped]

Reply to this message...
 
    
Morkai Kurst
As a quick addition, I was looking for more info earlier and was
looking at dotnetjunkies.com. It occured to me that the tutorials
index is almost exactly what i'm looking for. Looking at the 'view
source' I could see mention of classes. I'm all for delving deeper
into how asp.net can be used in a better structured and more reusable
manner. I was also looking at the iBuySpy apps for some help but
couldn't see anything that quite matched what I was trying to do
though.

Thanks

Morkai

[Original message clipped]

Reply to this message...
 
 
System.ComponentModel.Container
System.Data.DataRowView
System.Data.DataSet
System.EventArgs
System.Web.UI.WebControls.DataGrid
System.Web.UI.WebControls.DataList
System.Web.UI.WebControls.HyperLink
System.Web.UI.WebControls.RepeatDirection
System.Web.UI.WebControls.RepeatLayout
System.Windows.Forms.DataGrid




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com