Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > DataGrid does not display?

Reply
Thread Tools

DataGrid does not display?

 
 
Mervin Williams
Guest
Posts: n/a
 
      04-19-2004
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();
}


 
Reply With Quote
 
 
 
 
William Ryan eMVP
Guest
Posts: n/a
 
      04-19-2004
Set the datagrid.datasource =
cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
"Mervin Williams" <(E-Mail Removed)> wrote in message
news:uTe7$(E-Mail Removed)...
> 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();
> }
>
>



 
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
PC does not start and does not turn off sean Computer Support 3 12-28-2006 10:37 AM
How does a nested datagrid reference parent row in master datagrid? John Dalberg ASP .Net Datagrid Control 1 12-20-2005 06:45 PM
Power button does not turn OFF? New power supply does not help! win2k lbbss Computer Support 0 01-06-2005 04:03 PM
Webservice works once and then DOES NOT seem to work even though program does not crash Phi! ASP .Net Web Services 1 04-23-2004 08:42 AM
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible? Andreas Klemt ASP .Net Datagrid Control 0 10-08-2003 01:19 AM



Advertisments