DataGrid does not display?

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();
}
 
W

William Ryan eMVP

Set the datagrid.datasource =
cmd.ExecuteReader(CommandBehavior.CloseConnection);
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top