how to force display of datagrid with empty datasource

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
 
G

Guest

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.
 
G

Guest

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top