Data grid!

  • Thread starter Thread starter rcoco
  • Start date Start date
R

rcoco

hi,
I'm having problem with seeing my datagrid? Yet I set Property visible
to true and I'm caling the DataBind() what could be the Problem. I
mayed be forgetting something.. Could you please help?
Thanks?
 
Hi Rococo,

Paste some code so we could investigate.
--
Milosz





- Show quoted text -

hi miloz,
here is the code I'm using.

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

}
}

private void BindDataGrid()
{

SqlDataAdapter myAdapter=new SqlDataAdapter("SELECT * from
Billing",con);
DataSet ds=new DataSet();
myAdapter.Fill(ds);
con.Open();

dgbilling.DataSource=ds;
dgbilling.DataBind();
con.Close();
}

Thanks.
 
You're opening connection after Filling the dataset: You should always open
connection first (i amended the code a little bit):

private void BindDataGrid()
{

SqlDataAdapter myAdapter=new SqlDataAdapter("SELECT * from Billing", con);
DataSet ds = new DataSet();

try
{
con.Open():
myAdapter.Fill(ds);
}
catch
{
throw;
}
finally
{
con.Close();
}

dgbilling.DataSource = ds;
dgbilling.DataBind();

}

Hope it helps

Milosz
 
Thanks Miloz but it did not work.. I wonder why it does not work yet I
used the same code and it worked on a different project..
Thanks
 
Hi there again,

Did you check if the query is returning any results? Put a breakpoint at
dgbilling.DataSource = ds
and watch for quick ds.Tables[0].Rows.Count value.
 
Thanks Miloz but it did not work.. I wonder why it does not work yet I
used the same code and it worked on a different project..
Thanks

Can we see the code in the aspx file for the data grid?
Also I are you sure your query is bringing back data?
 
Back
Top