[Mono-list] ASP.NET - DataGrid DataBinding
Timothy Parez
Timothy Parez" <timothyparez@linux.be
Fri, 27 Jun 2003 00:31:08 +0200
This is a multi-part message in MIME format.
------=_NextPart_000_0005_01C33C43.66D8B760
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Hi,
Is it normal this code doesn't work yet ?
It doesn't throw any exceptions, and the datagrid actually gets the =
columns from the database
so I can see "id","name","description","status","author" as the headers =
for the columns, but it doesn't show the records.
-------------------------------------------------------------------------=
-----------------------------------------------
<%@ Page Language=3D"C#" %>
<%@ import Namespace=3D"ByteFX.Data.MySQLClient" %>
<%@ import Namespace=3D"System.Data" %>
<script runat=3D"server">
// Insert page code here
//
=20
void Page_Load(object sender, EventArgs e) {
=20
//Create a new connection object
MySQLConnection dbConnection =3D new MySQLConnection(@"Data =
Source=3Dlocalhost;Port=3D3306;Database=3Ddev;User =
ID=3Drded;Password=3Dsdec4;COMMAND LOGGIN=3Dfalse");
=20
//Create the query string
string sqlQuery =3D "SELECT * FROM object";
=20
//Create a new command object
MySQLCommand dbCommand =3D new =
MySQLCommand(sqlQuery,dbConnection);
=20
//Open the connection
dbConnection.Open();
=20
//Create a new DataAdapter
MySQLDataAdapter dbAdapter =3D new MySQLDataAdapter(dbCommand);
=20
//Create a new DataSet
DataSet dbObjects =3D new DataSet();
=20
//Fill it
dbAdapter.Fill(dbObjects,"objects");
=20
//Close the data adapter
dbConnection.Close();
=20
//Bind
dgrObjects.DataSource =3D dbObjects.Tables["objects"];
dgrObjects.DataBind();
=20
}
</script>
<html>
<head>
</head>
<body>
<form runat=3D"server">
<p>
</p>
<p>
</p>
<p>
<strong>Current objects:</strong>=20
</p>
<p>
<asp:DataGrid id=3D"dgrObjects" runat=3D"server" =
Width=3D"100%" BorderStyle=3D"None" BorderWidth=3D"1px" =
BorderColor=3D"#CCCCCC" BackColor=3D"White" CellPadding=3D"3">
<FooterStyle forecolor=3D"#000066" =
backcolor=3D"White"></FooterStyle>
<HeaderStyle font-bold=3D"True" forecolor=3D"White" =
backcolor=3D"#006699"></HeaderStyle>
<PagerStyle horizontalalign=3D"Left" =
forecolor=3D"#000066" backcolor=3D"White" =
mode=3D"NumericPages"></PagerStyle>
<SelectedItemStyle font-bold=3D"True" =
forecolor=3D"White" backcolor=3D"#669999"></SelectedItemStyle>
<ItemStyle forecolor=3D"#000066"></ItemStyle>
</asp:DataGrid>
<!-- Insert content here -->
</p>
</form>
</body>
</html>
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.491 / Virus Database: 290 - Release Date: 18/06/2003
------=_NextPart_000_0005_01C33C43.66D8B760
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dwindows-1252">
<META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Is it normal this code doesn't work yet =
?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>It doesn't throw any exceptions, and =
the datagrid=20
actually gets the columns from the database</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>so I can see=20
"id","name","description","status","author" as the headers for the =
columns, but=20
it doesn't show the records.</FONT></DIV>
<DIV><FONT face=3DArial=20
size=3D2>----------------------------------------------------------------=
--------------------------------------------------------</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2><%@ Page Language=3D"C#" =
%><BR><%@ import=20
Namespace=3D"ByteFX.Data.MySQLClient" %><BR><%@ import=20
Namespace=3D"System.Data" %><BR><script =
runat=3D"server"></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> // Insert page code=20
here<BR> //<BR> =
<BR> void=20
Page_Load(object sender, EventArgs e) {<BR> =20
<BR> //Create a new connection =
object<BR> MySQLConnection=20
dbConnection =3D new MySQLConnection(@"Data=20
Source=3Dlocalhost;Port=3D3306;Database=3Ddev;User =
ID=3Drded;Password=3Dsdec4;COMMAND=20
LOGGIN=3Dfalse");<BR> =20
<BR> //Create the query=20
string<BR> string sqlQuery =3D =
"SELECT *=20
FROM object";<BR> =20
<BR> //Create a new command=20
object<BR> MySQLCommand =
dbCommand =3D=20
new MySQLCommand(sqlQuery,dbConnection);<BR> =20
<BR> //Open the=20
connection<BR> =20
dbConnection.Open();<BR> =20
<BR> //Create a new=20
DataAdapter<BR> =
MySQLDataAdapter=20
dbAdapter =3D new MySQLDataAdapter(dbCommand);<BR> =20
<BR> //Create a new=20
DataSet<BR> DataSet dbObjects =
=3D new=20
DataSet();<BR> =
<BR> =20
//Fill it<BR> =20
dbAdapter.Fill(dbObjects,"objects");<BR> =20
<BR> //Close the data=20
adapter<BR> =20
dbConnection.Close();<BR> =20
<BR> =20
//Bind<BR> =
dgrObjects.DataSource =3D=20
dbObjects.Tables["objects"];<BR>  =
;=20
dgrObjects.DataBind();<BR> <BR> =20
}</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial=20
size=3D2></script><BR><html><BR><head><BR></head>=
<BR><body><BR> =20
<form =
runat=3D"server"><BR> =20
<p><BR> =20
</p><BR> =20
<p><BR> =20
</p><BR> =20
<p><BR> =
=20
<strong>Current objects:</strong>=20
<BR> =20
</p><BR> =20
<p><BR> =
=20
<asp:DataGrid id=3D"dgrObjects" runat=3D"server" Width=3D"100%" =
BorderStyle=3D"None"=20
BorderWidth=3D"1px" BorderColor=3D"#CCCCCC" BackColor=3D"White"=20
CellPadding=3D"3"><BR> =
=20
<FooterStyle forecolor=3D"#000066"=20
backcolor=3D"White"></FooterStyle><BR> &n=
bsp; =20
<HeaderStyle font-bold=3D"True" forecolor=3D"White"=20
backcolor=3D"#006699"></HeaderStyle><BR> =
=20
<PagerStyle horizontalalign=3D"Left" forecolor=3D"#000066" =
backcolor=3D"White"=20
mode=3D"NumericPages"></PagerStyle><BR> &=
nbsp; =20
<SelectedItemStyle font-bold=3D"True" forecolor=3D"White"=20
backcolor=3D"#669999"></SelectedItemStyle><BR> =
=
<ItemStyle=20
forecolor=3D"#000066"></ItemStyle><BR> &n=
bsp; =20
</asp:DataGrid><BR> =
=20
<!-- Insert content here =
--><BR> =20
</p><BR> =20
</form><BR></body><BR></html><BR></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><BR>---<BR>Outgoing mail is certified Virus Free.<BR>Checked by AVG =
anti-virus system (<A=20
href=3D"http://www.grisoft.com">http://www.grisoft.com</A>).<BR>Version: =
6.0.491 /=20
Virus Database: 290 - Release Date: =
18/06/2003</FONT></DIV></BODY></HTML>
------=_NextPart_000_0005_01C33C43.66D8B760--