DataGrid does not display?

Discussion in 'ASP .Net Datagrid Control' started by Mervin Williams, Apr 19, 2004.

  1. I placed a datagrid on my webform, set the datasource to a datareader, and
    bound the reader to the datagrid. However, my datagrid does not display.
    Here is my code from the Page_Load method:

    ====================================
    dgAgmtList = new DataGrid();
    SqlConnection con;
    string sql;
    SqlCommand cmd;
    SqlDataReader reader;

    sql = "SELECT * FROM [User] WHERE user_id='" + Page.User.Identity.Name +
    "'";
    con = new
    SqlConnection(ConfigurationSettings.AppSettings["OFS.ConnectionString"]);
    cmd = new SqlCommand(sql, con);
    con.Open();
    reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

    int rowcount = 0;
    if (reader.HasRows)
    {
    while(reader.Read())
    { rowcount++; }
    }

    if (rowcount == 0)
    {
    reader.Close();
    Server.Transfer("nextpage.aspx");
    }
    else
    {
    dgAgmtList.DataSource = reader;
    dgAgmtList.DataBind();
    reader.Close();
    }
    Mervin Williams, Apr 19, 2004
    #1
    1. Advertising

  2. Set the datagrid.datasource =
    cmd.ExecuteReader(CommandBehavior.CloseConnection);
    "Mervin Williams" <> wrote in message
    news:uTe7$...
    > I placed a datagrid on my webform, set the datasource to a datareader, and
    > bound the reader to the datagrid. However, my datagrid does not display.
    > Here is my code from the Page_Load method:
    >
    > ====================================
    > dgAgmtList = new DataGrid();
    > SqlConnection con;
    > string sql;
    > SqlCommand cmd;
    > SqlDataReader reader;
    >
    > sql = "SELECT * FROM [User] WHERE user_id='" + Page.User.Identity.Name +
    > "'";
    > con = new
    > SqlConnection(ConfigurationSettings.AppSettings["OFS.ConnectionString"]);
    > cmd = new SqlCommand(sql, con);
    > con.Open();
    > reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    >
    > int rowcount = 0;
    > if (reader.HasRows)
    > {
    > while(reader.Read())
    > { rowcount++; }
    > }
    >
    > if (rowcount == 0)
    > {
    > reader.Close();
    > Server.Transfer("nextpage.aspx");
    > }
    > else
    > {
    > dgAgmtList.DataSource = reader;
    > dgAgmtList.DataBind();
    > reader.Close();
    > }
    >
    >
    William Ryan eMVP, Apr 19, 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. Mervin Williams

    DataGrid does not display?

    Mervin Williams, Apr 19, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    364
    William Ryan eMVP
    Apr 19, 2004
  2. Imran Aziz
    Replies:
    4
    Views:
    1,503
    Imran Aziz
    Aug 11, 2005
  3. sunny
    Replies:
    5
    Views:
    301
    Clever Monkey
    Sep 20, 2006
  4. mholli

    Datagrid does not display

    mholli, Oct 22, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    1
    Views:
    94
    Alvin Bruney
    Oct 23, 2003
  5. sed_y
    Replies:
    0
    Views:
    997
    sed_y
    Feb 15, 2012
Loading...

Share This Page