[Mono-list] DataList and Mono
Tracy Barlow
tracy@aic.net.au
Tue, 30 Dec 2003 00:34:14 +1000
The following Code works fine with Windows 2000 server and IIS, but does
not work with Linux/Apache/Mod-Mono/and mono0.29, it crashes with an
invalid path error.
<% @Page Language="C#" %>
<% @Import Namespace="System" %>
<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Web" %>
<% @Import Namespace="ByteFX.Data" %>
<script runat="server">
private ByteFX.Data.MySqlClient.MySqlConnection oCN;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
LoadData();
}
}
public void Menu_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)
{
}
public void Article1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e)
{
}
private void LoadData()
{
try
{
DataOpen("Initial Catalog=myresume;Data
Source=laptoplinux;User ID=sa;password=qa23m0t0;");
System.Collections.ArrayList oParms = new
System.Collections.ArrayList();
string StoredProcedure;
StoredProcedure = "SELECT * FROM menu WHERE MenuGroup =
'HomePage'";
System.Data.DataSet DS = GetRows(StoredProcedure,
"Menu", "Menu");
DS.Tables["Menu"].DefaultView.Sort = "MenuItem";
DS.Tables["Menu"].DefaultView.RowFilter =
"MenuGroup='HomePage'";
Menu.DataSource = DS.Tables["Menu"].DefaultView;
Menu.DataBind();
// oParms.Clear()
// StoredProcedure = LocalPath.StoredProcPath
& "List_Article.sql"
// oParms.Add("@PageType='HomePage'")
//
// DS.Clear()
// DS = GD.GetRows(StoredProcedure,
"Article", "Article")
//
// DS.Tables["Article"].DefaultView.Sort =
"DisplayOrder"
// DS.Tables["Article"].DefaultView.RowFilter
= "PageType='HomePage'"
// Article1.DataSource =
DS.Tables["Article"].DefaultView
//
// Article1.DataBind()
Message.Text = aStr + " " + xStr;
}
catch (Exception myException)
{
Message.Text = myException.Message;
// Throw (New Exception(myException.Message &
" - " & myException.Source))
}
//
DataClose();
}
private void DataOpen(string sqlConnectionString)
{
oCN = new
ByteFX.Data.MySqlClient.MySqlConnection(sqlConnectionString);
try
{
oCN.Open();
}
catch (Exception myException)
{
string aStr = myException.Message;
throw (new Exception(myException.Message + " - " +
myException.Source));
}
}
protected void DataClose()
{
try
{
oCN.Close();
}
catch
{
}
try
{
oCN.Dispose();
}
catch
{
}
}
public System.Data.DataSet GetRows(string StoredProc, string
DataSetName, string TableName)
//******************************************************************************************//
{
// Author: Tracy Anne Barlow
// Date: September 2001
// Method Name: Retreive
// Description: Retrieve Data using either a Stored
procudure (name passed in QueryName) or
// a SQl query String (passed in QueryName)
// The Parameter Values for a Stored Procedure
are passed in the Optional
// Parameters variable
//
// Returns a Dataset which contains the Data
returned from the Database
//******************************************************************************************//
ByteFX.Data.MySqlClient.MySqlCommand oCMD = new
ByteFX.Data.MySqlClient.MySqlCommand(StoredProc, oCN);
ByteFX.Data.MySqlClient.MySqlDataAdapter da = new
ByteFX.Data.MySqlClient.MySqlDataAdapter();
System.Data.DataSet ds = new System.Data.DataSet(DataSetName);
try
{
da.SelectCommand = oCMD;
da.Fill(ds, TableName);
return ds;
}
catch (Exception myException)
{
string aStr = myException.Message;
throw (new Exception(myException.Message + " - " +
myException.Source));
}
}
</script>
<html>
<head>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR" />
<meta content="C#" name="CODE_LANGUAGE" />
<meta content="JavaScript" name="vs_defaultClientScript" />
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema" />
</head>
<body text="#000000" vlink="#666666" link="#800000" bgcolor="#ffffff"
leftmargin="0" background="images/tasback.gif" topmargin="0">
<form id="Form1" method="post" runat="server">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<img height="1" src="images/_blnk.gif" width="9"
/></td>
</tr>
<tr>
<td width="9" height="9">
</td>
</tr>
<tr>
<td height="126">
</td>
<td valign="top" align="left" width="56" colspan="3"
height="126" rowspan="1">
<img height="126" src="images/tasimg0.gif"
width="514" border="0" /></td>
<td valign="top" align="left" width="95%"
colspan="1" height="126" rowspan="1">
<img height="126" src="images/tasimg1.gif"
width="100%" border="0" /></td>
<td valign="top" align="left" width="10" colspan="1"
height="126" rowspan="1">
<img height="126" src="images/tasimg2.gif"
width="10" border="0" /></td>
</tr>
</tbody>
</table>
<table cellspacing="0" cellpadding="10" width="100%" border="0">
<tbody>
<tr>
<td align="middle" colspan="2">
<asp:Label id="Message" text="Bugger"
runat="server"></asp:Label></td>
</tr>
<tr>
<td valign="top" width="150" rowspan="5">
<asp:datalist id="Menu" Runat="server"
BorderStyle="None" Width="100%" RepeatDirection="Vertical"
RepeatColumns="0" Font-Name="Verdana" EnableViewState="True"
DataKeyField="MenuID" CellSpacing="0" CellPadding="5" ShowFooter="false"
ShowHeader="False" ItemStyle-VerticalAlign="middle"
ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:HyperLink NavigateUrl='<%#
DataBinder.Eval(Container.DataItem, "MenuPath") %>' id="MenuItem"
runat="server" style="BACKGROUND-COLOR: transparent" Text='<%#
DataBinder.Eval(Container.DataItem, "MenuText") %>' Font-Name="verdana"
Font-Size="8"></asp:HyperLink>
</ItemTemplate>
</asp:datalist>
</td>
<td valign="top" align="left">
<asp:datalist id="Article1" Runat="server"
BorderStyle="None" Width="100%" RepeatDirection="Vertical"
RepeatColumns="0" Font-Name="Verdana" EnableViewState="True"
OnItemDataBound="Article1_ItemDataBound" DataKeyField="DisplayOrder"
CellSpacing="0" CellPadding="5" ShowFooter="false" ShowHeader="False"
ItemStyle-VerticalAlign="top" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label id="Article" runat="server"
style="BACKGROUND-COLOR: transparent" text='<%#
System.Text.Encoding.ASCII.GetString((byte[])DataBinder.Eval(Container.DataItem,
"Article")) %>' font-name="verdana" font-size="8"></asp:Label>
</ItemTemplate>
</asp:datalist>
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Server error in '/' application
Invalid path.
Description: Error processing request.
Error Message: Invalid path.
Stack Trace:
System.Web.HttpException: Invalid path.
in <0x00197> System.Web.Util.UrlUtils:Reduce (string)
in <0x00218> System.Web.Util.UrlUtils:Combine (string,string)
in <0x00119> System.Web.UI.Control:ResolveUrl (string)
in <0x00062> System.Web.UI.WebControls.HyperLink:AddAttributesToRender
(System.Web.UI.HtmlTextWriter)
in <0x00016> System.Web.UI.WebControls.WebControl:RenderBeginTag
(System.Web.UI.HtmlTextWriter)
in <0x00011> System.Web.UI.WebControls.WebControl:Render
(System.Web.UI.HtmlTextWriter)
in <0x0001c> System.Web.UI.Control:RenderControl
(System.Web.UI.HtmlTextWriter)
in <0x000d8> System.Web.UI.Control:RenderChildren
(System.Web.UI.HtmlTextWriter)
in <0x00011> System.Web.UI.Control:Render (System.Web.UI.HtmlTextWriter)
in <0x0000d> System.Web.UI.WebControls.WebControl:RenderContents
(System.Web.UI.HtmlTextWriter)
in <0x002b2> System.Web.UI.WebControls.DataListItem:RenderItem
(System.Web.UI.HtmlTextWriter,bool,bool)
in <0x0006b>
System.Web.UI.WebControls.DataList:System.Web.UI.WebControls.IRepeatInfoUser.RenderItem
(System.Web.UI.WebControls.ListItemType,int,System.Web.UI.WebControls.RepeatInfo,System.Web.UI.HtmlTextWriter)
in <0x00401> System.Web.UI.WebControls.RepeatInfo:DoVerticalRendering
(System.Web.UI.HtmlTextWriter,System.Web.UI.WebControls.IRepeatInfoUser,System.Web.UI.WebControls.Style,System.Web.UI.WebControls.WebControl)
in <0x00035> System.Web.UI.WebControls.RepeatInfo:RenderRepeater
(System.Web.UI.HtmlTextWriter,System.Web.UI.WebControls.IRepeatInfoUser,System.Web.UI.WebControls.Style,System.Web.UI.WebControls.WebControl)
in <0x001f4> System.Web.UI.WebControls.DataList:RenderContents
(System.Web.UI.HtmlTextWriter)
in <0x00020> System.Web.UI.WebControls.BaseDataList:Render
(System.Web.UI.HtmlTextWriter)
in <0x0001c> System.Web.UI.Control:RenderControl
(System.Web.UI.HtmlTextWriter)
in <0x000d8> System.Web.UI.Control:RenderChildren
(System.Web.UI.HtmlTextWriter)
in <0x00049> System.Web.UI.HtmlControls.HtmlForm:RenderChildren
(System.Web.UI.HtmlTextWriter)
in <0x00023> System.Web.UI.HtmlControls.HtmlContainerControl:Render
(System.Web.UI.HtmlTextWriter)
in <0x0004a> System.Web.UI.HtmlControls.HtmlForm:Render
(System.Web.UI.HtmlTextWriter)
in <0x0001c> System.Web.UI.Control:RenderControl
(System.Web.UI.HtmlTextWriter)
in <0x000d8> System.Web.UI.Control:RenderChildren
(System.Web.UI.HtmlTextWriter)
in <0x00011> System.Web.UI.Control:Render (System.Web.UI.HtmlTextWriter)
in <0x0001c> System.Web.UI.Control:RenderControl
(System.Web.UI.HtmlTextWriter)
in <0x00188> System.Web.UI.Page:ProcessRequest (System.Web.HttpContext)
in <0x00191> .ExecuteHandlerState:Execute ()
in <0x00076> .StateMachine:ExecuteState
(System.Web.HttpApplication/IStateHandler,bool&)
If I comment ou the line Menu.DataBind(); it does not crash.
If I remove the DataBinder.Eval(Container.DataItem, "MenuText") and
DataBinder.Eval(Container.DataItem, "MenuPath") code and replace then
with "Some Text" it does not crash.
What is missing, or invalid for Mono on Linux.