在asp.net中始终显示gridview标头
问题描述:
我有一个GridView,并且我也想在gridview数据源也为null时显示gridview标头,应该遵循的方式是什么?
谢谢.
I have a GridView and I want to show the gridview header when gridview data source is null too.What will be the way that should I follow?
Thank you.
答
您好,这里考虑dtCustomer是包含您的数据的DataTable.
代码在下面
Hi, here consider dtCustomer is DataTable which contains your Data.
code is below
if (dtCustomer != null)
{
if (dtCustomer.Rows.Count > 0)
{
GridView1.DataSource = dtCustomer;
GridView1.DataBind();
}
else
{
dtCustomer.Rows.Add(dtCustomer.NewRow());
GridView1.DataSource = dtCustomer;
GridView1.DataBind();
int TotalColumns = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = TotalColumns;
GridView1.Rows[0].Cells[0].Text = "No Data";
}
}
else
{
//Here if you want, you can call the inner else condition code here
}