Datagrid doesnt populate :(

L

Lasse Edsvik

Hello

Im trying to do a simple page with data from my local sql server, and page
just shows up blank...... I created a stored procedure with SELECT * FROM
Employees......

whats wrong?


using System;

using System.Configuration;

using System.Data;

using System.Data.SqlClient;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

namespace dbtest

{

/// <summary>

/// Summary description for WebForm1.

/// </summary>

public class WebForm1 : System.Web.UI.Page

{

protected System.Web.UI.WebControls.DataGrid DataGrid1;


private void Page_Load(object sender, System.EventArgs e)

{


SqlConnection conn = new
SqlConnection("server=localhost;uid=sa;pwd=;database=northwind");

SqlCommand cmd = new SqlCommand("EmployeesList", conn);

cmd.CommandType = CommandType.StoredProcedure;

conn.Open();


DataGrid1.DataSource = cmd.ExecuteReader(Commandbehaviour.CloseConnection);

DataGrid1.DataBind();

// Put user code to initialize the page here

}


#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}


/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.Load += new System.EventHandler(this.Page_Load);

}

#endregion

}

}









then:

<%@ Page language="c#" Codebehind="Webform1.aspx.cs" AutoEventWireup="false"
Inherits="dbtest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
&nbsp;
<asp:datagrid id="DataGrid1" runat="server" />

</form>
</body>
</HTML>
 
M

Martin Dechev

Hi,

First, are you sure the stored procedure returns results?

Second, it might be the case when aspx pages don't get processed (see
http://support.microsoft.com/?kbid=325093). try inserting a Label on the
page and setting its Text property from the code-behind class to see if it's
rendered correctly.

Hope this helps
Martin
 
B

Ben Lucas

Have you compiled your code?

I checked your program and if its written exactly as it is in here, it won't
compile because "CommandBehavior" is mispelled "Commandbehaviour". Also
remember that case is important in C#.

When I corrected this and compiled the application, the DataGrid showed all
of the records.
 
L

Lasse Edsvik

Martin,

It returns 9, im very sure........

something fishy is going on....... i put in Response.Write("test") and
still the page shows up blank......

i put in "test" in the html-part of the page and it shows....... why isnt
Page_Load event triggered?
 
L

Lasse Edsvik

Martin,

and...... there is no serverside code in "view source"....

i've done some tests with asp.net and they have been executed, not sure what
went wrong in this case
 
L

Lasse Edsvik

Ben,

thx :D

second case sensitive thing ive done today........

thanks again :)
/Lasse
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top