how to force display of datagrid with empty datasource

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi guys,

I need to use a one row datagrid in my asp.net 1.1 application. The data
source will contain 1 or 0 entries. When no rows of data are present I want
to show an empty row in the datagrid (ie. with empty cells). Unfortunatly I
get no datagrid shown instead. Any idea how I can force the datagrid to show
with an empty row?

Best regards,

Jose Carballosa
 
you could test for rows and if row.count=0 then set up a virtual DataTable,
new DataRow with no values (or empty values) then DataTable.AddRow and
databind to this datasource.
 
Suppose you use datatable as the datagrid's data source, you can easily show
an empty row when no data by following method:

// fill datatable
if(datatable.Rows.Count == 0)
{
datatable.Rows.Add(datatable.NewRow);
}
datagrid.DataSource = datatable;
datagrid.DataBind();

HTH

Elton Wang
(e-mail address removed)
 
Back
Top