If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Applications & Tools > Web Matrix Question - Datagrid vs Datalist

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-12-05, 20:09
kennyharrill kennyharrill is offline
Registered User
 
Join Date: Aug 2005
Posts: 24
Web Matrix Question - Datagrid vs Datalist

I am attaching two sample scripts. The first one I copied from a textbook I'm reading on ASP.NET

<%@ Page Explicit="True" Language="VB" Debug="True" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(Sender As Object, E as EventArgs)
If Not IsPostBack Then
Dim Connect As OleDbConnection = New OleDbConnection
Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter
Dim ClassyDS As DataSet = New DataSet
Dim ConnectString, SelectStatement As String
Dim Category As String
Category = Trim(Request.QueryString("Category"))

If Category <> "" Then
Header.Text = "Ad Listing:" & Category
SelectStatement = _
"Select * From Ads Where Category='" & _
Category & "'"
Else
Header.Text = "Ad Listing"
SelectStatement = "Select * From Ads"
End If

ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data source=C:\inetpub\wwwroot\simplyclassy\classydb.md b"

Connect.ConnectionString = ConnectString
Adapter.SelectCommand = _
new OleDbCommand(SelectStatement, Connect)
Adapter.SelectCommand.Connection.Open
Adapter.Fill(ClassyDS,"Ads")
AdsGrid.DataSource = ClassyDS.Tables("Ads")
Page.DataBind
End If
End Sub

</script>
<html>
<head>
</head>
<body vlink="red">
<asp:Label id="Header" font-bold="true" font-size="18 pt" runat="server"></asp:Label>
<br />
<br />
<asp:datagrid id="AdsGrid" runat="server" autogeneratecolumns="false" border="1" backcolor="white" width="100%" bordercolor="black" cellspacing="0" cellpadding="5">
<HeaderStyle font-names="courier" font-bold="True"></HeaderStyle>
<AlternatingItemStyle backcolor="Olive"></AlternatingItemStyle>
<Columns>
<asp:hyperlinkcolumn headertext="Email" datanavigateurlfield="EMail" datatextfield="Email" />
<asp:BoundColumn DataField="Price" HeaderText="Price"></asp:BoundColumn>
<asp:BoundColumn DataField="State" HeaderText="State"></asp:BoundColumn>
</Columns>
</asp:datagrid>
<br />
<center>
<asp:hyperlink id="HomeLink" font-bold="true" font-size="12 pt" runat="server" font-name="Arial" navigateurl="default.aspx">
[ Home ]</asp:hyperlink>
</center>
</body>
</html>


The second is an actual script from a website of mine that I'm in the process of revamping, using ASP.NET, Web Matrix and a Microsoft Database:

<%@ Page Explicit="True" Language="VB" Debug="True" %>
<%@ Register TagPrefix="ASPFD" TagName="Header" Src="topportion.ascx" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

Sub Page_Load(Sender As Object, E as EventArgs)
If Not IsPostBack Then
Dim Connect As OleDbConnection = New OleDbConnection
Dim Adapter As OleDbDataAdapter = New OleDbDataAdapter
Dim ClassyDS As DataSet = New DataSet
Dim ConnectString, SelectStatement As String
Dim Mycategory As String
Mycategory = Trim(Request.QueryString("Mycategory"))

If Mycategory <> "" Then
SelectStatement = _
"Select * From artscluster Where Mycategory='" & _
Mycategory & "'"
Else
SelectStatement = "Select * From artscluster"
End If

ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data source=C:\inetpub\wwwroot\mydirectory\mydatabase.m db"

Connect.ConnectionString = ConnectString
Adapter.SelectCommand = _
new OleDbCommand(SelectStatement, Connect)
Adapter.SelectCommand.Connection.Open
Adapter.Fill(ClassyDS,"artscluster")
AdsGrid.DataSource = ClassyDS.Tables("artscluster")
Page.DataBind
End If
End Sub

</script>
<html>
<head>
<script language="javascript">
function DisplayMenu(stobj, stbullet)
{
var obj = document.getElementById(stobj);
var bullet = document.getElementById(stbullet);

if(obj.className == "submenu_hide")
{
obj.className = "submenu_show";
bullet.src = "images/menubullet_up.gif";
}
else
{
obj.className = "submenu_hide";
bullet.src = "images/menubullet_down.gif";
}
}
function testit()
{
}
</script>
<link href="styles/StyleSheet1.css" rel="stylesheet" />
</head>
<body>
<form runat="server">
<aspfd:header id="UserControl1" runat="server"></aspfd:header>
<td class="mainbody" bgcolor="#ffffff" width="645" align="top" valign="top">
<div class="mainbody">
<table cellspacing="0" cellpadding="3" border="0">
<tbody>
<tr>
<td>
</td>
</tr>
</tbody>
</table>
</div>
<br />
<marquee>Americus/Sumter County Arts Resources</marquee>
<br />
<br />
<asp:datalist id="AdsGrid" runat="server" width="100%" cellpadding="2" cellspacing="0" bordercolor="black" backcolor="white" border="1">
<HeaderStyle font-names="timesnewroman" font-bold="True" font-size="12pt"></HeaderStyle>
<AlternatingItemStyle backcolor="Orange"></AlternatingItemStyle>
<ItemTemplate>
<b><%# Container.DataItem("Name")%></b>
<br />
<%# Container.DataItem("Address")%>
<br />
<%# Container.DataItem("City")%>, <%# Container.DataItem("State")%> <%# Container.DataItem("Zip")%>
<br />
<%# Container.DataItem("Phone")%>
<br />
</ItemTemplate>
</asp:datalist>
</td>
<center>
</center>
</form>
</body>
</html>

In the first script, the header.text statement will work in the If..End If statement, but when I try to use it in the datalist, I'm getting an error that header is not declared. I tried declaring Header as a variable, then using header.text (and also headertext as one word), but I'm told that text is not a property of header. I'm wanting to display text right above my datalist, preferably the result of the querystring itself. Can someone tell me how or if that will be possible. I"m anxious to get this site wrapped up ASAP. Thanks!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On