Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Datagrid doesnt populate :(

Reply
Thread Tools

Datagrid doesnt populate :(

 
 
Lasse Edsvik
Guest
Posts: n/a
 
      09-23-2004
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...... returns 9 rows in QA

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=;databa se=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>



 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      09-26-2004
Wouldn't you want to uses a dataadapter and get the data into a Dataset
rather than use a reader?

"Lasse Edsvik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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...... returns 9 rows in QA
>
> 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=;databa se=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>
>
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sort list doesnt work, key=str still doesnt work notnorwegian@yahoo.se Python 3 05-27-2008 04:32 AM
PC doesnt boot first time and doesnt shutdown dann Computer Support 6 08-21-2006 07:31 AM
Populate a popup window with clickable records from an Access DB and upon clicking, populate a selectbox on the original webpage with the clicked record Enjoy Life ASP General 2 02-23-2005 10:48 PM
Datagrid doesnt populate :( Lasse Edsvik ASP .Net 5 09-23-2004 02:21 PM
How can I select items in a datagrid to populate a second datagrid. Eric ASP .Net Datagrid Control 5 08-04-2004 12:43 AM



Advertisments