C# Datagrid Blank

R

rex64

I created a datagrid and it worked great in the regular C#. But when I
do the exact same thing in ASP it does not work.

private void btnSignUp_Click(object sender, System.EventArgs e)
{
string connectionString="data source=JEFF-3KQH2O8TJF;initial
catalog=studyXSQL3;Integrated Security=SSPI";
SqlConnection studyXconnection=new SqlConnection(connectionString);
string selectStatement = "SELECT postID, userName, Post, Date,
Views "
//+ "ProductTotal, SalesTax, ShippingAndHandling, InvoiceTotal "
+ "FROM Posts ";
// + "WHERE CustomerID = @CustomerID "
// + "ORDER BY InvoiceID";
//studyXconnection.Open();
//SqlCommand selectCommand = new SqlCommand(selectStatement,
studyXconnection);
//selectCommand.ExecuteNonQuery();
SqlDataAdapter invoicesDataAdapter = new
SqlDataAdapter(selectStatement, studyXconnection);
DataSet invoicesDataSet = new DataSet();
invoicesDataAdapter.Fill(invoicesDataSet, "Posts");
grdPosts.AutoGenerateColumns = true;
grdPosts.DataSource = invoicesDataSet.Tables["Posts"];
invoicesDataAdapter.Update(invoicesDataSet,"Posts");
//grdPosts.
//studyXconnection.Close();
}
 
C

Chris Jobson

rex64 said:
I created a datagrid and it worked great in the regular C#. But when I
do the exact same thing in ASP it does not work.

private void btnSignUp_Click(object sender, System.EventArgs e)
{
string connectionString="data source=JEFF-3KQH2O8TJF;initial
catalog=studyXSQL3;Integrated Security=SSPI";
SqlConnection studyXconnection=new SqlConnection(connectionString);
string selectStatement = "SELECT postID, userName, Post, Date,
Views "
//+ "ProductTotal, SalesTax, ShippingAndHandling, InvoiceTotal "
+ "FROM Posts ";
// + "WHERE CustomerID = @CustomerID "
// + "ORDER BY InvoiceID";
//studyXconnection.Open();
//SqlCommand selectCommand = new SqlCommand(selectStatement,
studyXconnection);
//selectCommand.ExecuteNonQuery();
SqlDataAdapter invoicesDataAdapter = new
SqlDataAdapter(selectStatement, studyXconnection);
DataSet invoicesDataSet = new DataSet();
invoicesDataAdapter.Fill(invoicesDataSet, "Posts");
grdPosts.AutoGenerateColumns = true;
grdPosts.DataSource = invoicesDataSet.Tables["Posts"];
invoicesDataAdapter.Update(invoicesDataSet,"Posts");
//grdPosts.
//studyXconnection.Close();
}

Not sure, but I think you have to call grdPosts.DataBind() after setting
grdPosts.DataSource.

Chris Jobson
 
R

rex64

Yup, that is all it was. Thanks a million!!!!!!!! You dont know how
much time I spent trying to get this to work.
 
T

tdavisjr

Seeing this type of code makes me wonder. I sure hope this is sample
code and not placed in production, this would be a total nightmare to
maintain if it was.
 
Top