void page_load(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("server='(local)'; trusted_connection=true; database='mattsDEMO'"); SqlDataAdapter myCommand = new SqlDataAdapter("select * from people", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "people");
MyDataGrid.DataSource=ds.Tables["people"].DefaultView;
MyDataGrid.DataBind();
}
When I place a data grid controll on my page named myDataGrid, I do not see a data grid and there is no data either. The code in the HTML looks like this:
<body>
<form runat="server">
<p>
<asp:DataGrid id="myDataGrid" runat="server" BorderColor="Maroon"></asp:DataGrid>
</p>
</form>
</body>
I tried using debug that comes with the .Net framework (since I am using Web Matrix) but I get an error saying no symbols were found for this document when setting break points. What are symbols and why do I need them?
So, I basically have four (4) important questions that I need help answering:
1) Why do I not have any data in my data grid?
2) Where did myDataGrid come from?
3) Is the page_Load method called by default if auto wire is set to true or not declared?
4) Why do I need symbols for debug?
Below is all my code in one complete view:
<%@. Page Language="C#" %>
<%@. 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.SqlClient" %>
<script runat="server">
// Insert page code here
//
</script>
<html>
<head>
<script language="C#">
void page_load(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection("server='(local)'; trusted_connection=true; database='mattsDEMO'");
SqlDataAdapter myCommand = new SqlDataAdapter("select * from people", myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds, "people");
MyDataGrid.DataSource=ds.Tables["people"].DefaultView;
MyDataGrid.DataBind();
}
</script>
</head>
<body>
<form runat="server">
<p>
</p>
<p>
<asp:Label id="Label1" runat="server">This is a test!</asp:Label>
</p>
<p>
<asp:DataGrid id="myDataGrid" runat="server" BorderColor="Maroon"></asp:DataGrid>
</p>
</form>
</body>
</html>
Thanks,
Ryan
(2) You could set the autogeneratecolumns property of the datagrid to true. I am not good at C#. So I wouldnt try writing code for you.
No comments:
Post a Comment