Datagrid doesnt populate :(

Discussion in 'ASP .Net Datagrid Control' started by Lasse Edsvik, Sep 23, 2004.

  1. Lasse Edsvik

    Lasse Edsvik Guest

    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=;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>
     
    Lasse Edsvik, Sep 23, 2004
    #1
    1. Advertising

  2. Wouldn't you want to uses a dataadapter and get the data into a Dataset
    rather than use a reader?

    "Lasse Edsvik" <> wrote in message
    news:...
    > 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=;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>
    >
    >
    >
     
    Ken Cox [Microsoft MVP], Sep 26, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lasse Edsvik

    Datagrid doesnt populate :(

    Lasse Edsvik, Sep 23, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    440
    Lasse Edsvik
    Sep 23, 2004
  2. Dee

    DataGrid Paging doesnt page!

    Dee, Apr 18, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    2,271
    Scott M.
    Apr 19, 2005
  3. Replies:
    3
    Views:
    461
    alex23
    May 27, 2008
  4. Eric
    Replies:
    5
    Views:
    212
  5. Enjoy Life
    Replies:
    2
    Views:
    314
    Roland Hall
    Feb 23, 2005
Loading...

Share This Page