Link to home
Start Free TrialLog in
Avatar of kvnsdr
kvnsdr

asked on

ASP.NET C# BindGrid?

Okay, I've tried the infamous 'BindGrid' method with both VS 2003 Intellisense and manually, however I cannot seem to get a DataGrid to show on page_load. I've also noticed that Intellisense doesn't always include all the code sometimes. I simply have a Dataset filling a datagrid.

private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindGrid();
}                  
}

private void BindGrid()
{
string SQL="Select * FROM DataBaseTable";  
cn = new SqlConnection(ConfigurationSettings.AppSettings["AppSqlCon"]);
SqlCommand cmd= new SqlCommand(SQL,cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
cn.Open();
da.Fill(dataSet1, "datasetTable");
DataGrid1.DataSource = dataSet1.Tables["datasetTable"].DefaultView;
DataGrid1.DataBind();
}
cn.Close();

Avatar of martie_11
martie_11
Flag of United States of America image

What happens?  Do you get an error or just a blank screen?
Avatar of kvnsdr
kvnsdr

ASKER

Just a blank screen.
Can you paste the HTML from the ASPX page?

Thanks.
Avatar of Anandhi K
If you use BoundColumns for displaying, Have you given the DataField Property which is nothing
but the column that has to displayed in the DataGrid
<asp:BoundColumn HeaderText = "XXXX" DataField=<DataTable ColumnName>>
(Or)
If you want to bind the dataTable to the Grid give AutoGenerateColumns="True" while
defining datagrid

If these 2 are not solns. can you post Aspx page coding?
ASKER CERTIFIED SOLUTION
Avatar of NetSlut
NetSlut

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry , my comment wasnt finished yet.

Make sure this line " this.Load += new System.EventHandler(this.Page_Load); "

is included in the InitializeComponent() of the codebehind page.

Visual studio will often remove this line, so Page_Load won't be called and you keep getting a blank page.

This is a known (and very fun) bug in visual studio. :-)