GridView - Show headers on empty data source

后端 未结 16 1257
挽巷
挽巷 2020-11-28 11:22

In C# how do I still show the headers of a gridview, even with the data source is empty.

I am not auto generating the columns as they are all predefined.

C

16条回答
  •  失恋的感觉
    2020-11-28 12:15

    After posting this I did come up with a way that works. However, I don't feel it is the best way to handle this. Any suggestions on a better one?

    //Check to see if we get rows back, if we do just bind.
    
    if (dtFunding.Rows.Count != 0)
    {
        grdFunding.DataSource = dtFunding;
        grdFunding.DataBind();
    }
    else
    {
      //Other wise add a emtpy "New Row" to the datatable and then hide it after binding.
    
         dtFunding.Rows.Add(dtFunding.NewRow());
         grdFunding.DataSource = dtFunding;
         grdFunding.DataBind();
         grdFunding.Rows[0].Visible = false;
    }
    

提交回复
热议问题