M
Mervin Williams
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();
}
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();
}