[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>&nbsp;</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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&lt;%@ Page Language=3D"C#" =
%&gt;<BR>&lt;%@ import=20
Namespace=3D"ByteFX.Data.MySQLClient" %&gt;<BR>&lt;%@ import=20
Namespace=3D"System.Data" %&gt;<BR>&lt;script =
runat=3D"server"&gt;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; // Insert page code=20
here<BR>&nbsp;&nbsp;&nbsp; //<BR>&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp; void=20
Page_Load(object sender, EventArgs e) {<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Create a new connection =

object<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MySQLConnection=20
dbConnection =3D new MySQLConnection(@"Data=20
Source=3Dlocalhost;Port=3D3306;Database=3Ddev;User =
ID=3Drded;Password=3Dsdec4;COMMAND=20
LOGGIN=3Dfalse");<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Create the query=20
string<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sqlQuery =3D =
"SELECT *=20
FROM object";<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Create a new command=20
object<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MySQLCommand =
dbCommand =3D=20
new MySQLCommand(sqlQuery,dbConnection);<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Open the=20
connection<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
dbConnection.Open();<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Create a new=20
DataAdapter<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
MySQLDataAdapter=20
dbAdapter =3D new MySQLDataAdapter(dbCommand);<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Create a new=20
DataSet<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet dbObjects =
=3D new=20
DataSet();<BR>&nbsp;&nbsp;&nbsp; =
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
//Fill it<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
dbAdapter.Fill(dbObjects,"objects");<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Close the data=20
adapter<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
dbConnection.Close();<BR>&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
//Bind<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
dgrObjects.DataSource =3D=20
dbObjects.Tables["objects"];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp=
;=20
dgrObjects.DataBind();<BR>&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;=20
}</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&lt;/script&gt;<BR>&lt;html&gt;<BR>&lt;head&gt;<BR>&lt;/head&gt;=
<BR>&lt;body&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&lt;form =
runat=3D"server"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;/p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;/p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
&lt;strong&gt;Current objects:&lt;/strong&gt;=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;/p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;p&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
&lt;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"&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;FooterStyle forecolor=3D"#000066"=20
backcolor=3D"White"&gt;&lt;/FooterStyle&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;HeaderStyle font-bold=3D"True" forecolor=3D"White"=20
backcolor=3D"#006699"&gt;&lt;/HeaderStyle&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;PagerStyle horizontalalign=3D"Left" forecolor=3D"#000066" =
backcolor=3D"White"=20
mode=3D"NumericPages"&gt;&lt;/PagerStyle&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;SelectedItemStyle font-bold=3D"True" forecolor=3D"White"=20
backcolor=3D"#669999"&gt;&lt;/SelectedItemStyle&gt;<BR>&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =

&lt;ItemStyle=20
forecolor=3D"#000066"&gt;&lt;/ItemStyle&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;/asp:DataGrid&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;=20
&lt;!-- Insert content here =
--&gt;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
&lt;/p&gt;<BR>&nbsp;&nbsp;&nbsp;=20
&lt;/form&gt;<BR>&lt;/body&gt;<BR>&lt;/html&gt;<BR></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</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--