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(Configuratio nSettings. AppSetting s["AppSqlC on"]);
SqlCommand cmd= new SqlCommand(SQL,cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
cn.Open();
da.Fill(dataSet1, "datasetTable");
DataGrid1.DataSource = dataSet1.Tables["datasetTa ble"].Defa ultView;
DataGrid1.DataBind();
}
cn.Close();
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
BindGrid();
}
}
private void BindGrid()
{
string SQL="Select * FROM DataBaseTable";
cn = new SqlConnection(Configuratio
SqlCommand cmd= new SqlCommand(SQL,cn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
cn.Open();
da.Fill(dataSet1, "datasetTable");
DataGrid1.DataSource = dataSet1.Tables["datasetTa
DataGrid1.DataBind();
}
cn.Close();
What happens? Do you get an error or just a blank screen?
ASKER
Just a blank screen.
Can you paste the HTML from the ASPX page?
Thanks.
Thanks.
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?
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"
defining datagrid
If these 2 are not solns. can you post Aspx page coding?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry , my comment wasnt finished yet.
Make sure this line " this.Load += new System.EventHandler(this.P age_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. :-)
Make sure this line " this.Load += new System.EventHandler(this.P
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. :-)