I am using a Gridview with datasource is a List. How can I show the header if the List is null or for a empty gridview?
            Asked
            
        
        
            Active
            
        
            Viewed 7,514 times
        
    3 Answers
3
            
            
        if you are using fx4.0 then Set ShowHeaderWhenEmpty to true in Grid view
please look at below code
asp:GridView ID="gvPreview" runat="server" ShowHeaderWhenEmpty="True" 
        shanethehat
        
- 15,460
 - 11
 - 57
 - 87
 
        Naren Chejara
        
- 31
 - 2
 
0
            
            
        You can use HeaderTemplate property to setup the head programatically or use ListView instead if you are using .NET 3.5.
or
You can even try below
//if data exists
if (dtSource.Rows.Count != 0)
{
grdView.DataSource = dtSource;
grdView.DataBind();
}
else
{
 //Other wise add a emtpy "New Row" to the datatable and then hide it after binding.
 dtFunding.Rows.Add(dtSource.NewRow());
 grdView.DataSource = dtSource;
 grdView.DataBind();
 grdView.Rows[0].Visible = false;
}
        Sauron
        
- 16,668
 - 41
 - 122
 - 174
 
        Ravi Vanapalli
        
- 9,805
 - 3
 - 33
 - 43