如何显示“未找到记录”?在GridView asp.net中的列? [英] How to show "No record found" with Columns in GridView asp.net?
本文介绍了如何显示“未找到记录”?在GridView asp.net中的列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我将数据源绑定到GridView时,如果它在我的数据源中没有记录,它将不会显示任何内容。
When I bind data source to GridView, if it has no record in my data source, it will not display anything.
如果我将数据设置为EmptyDataText属性在GridView中,它只会显示该文本。
If I set the data to EmptyDataText property in GridView, it will show only that text.
,但是我想显示数据源的一列,并且第一行必须在我的显示未找到记录网格视图。我应该怎么办?
,But I want to show a Column of my data source and the first row must display "No record found" in my GridView. What should I do?
推荐答案
当数据表为空时,创建一个新行并绑定,将那之后的columspan设置为单元格计数。
When a datatable is empty, create a new row and and bind after that set columspan to cell count.
DataTable dtTable = GetData();
if (dtTable.Rows.Count > 0)
{
gvDetails.DataSource = dtTable;
gvDetails.DataBind();
}
else
{
dtTable.Rows.Add(dtTable.NewRow());
gvDetails.DataSource = dtTable;
gvDetails.DataBind();
int TotalColumns = gvDetails.Rows[0].Cells.Count;
gvDetails.Rows[0].Cells.Clear();
gvDetails.Rows[0].Cells.Add(new TableCell());
gvDetails.Rows[0].Cells[0].ColumnSpan = TotalColumns;
gvDetails.Rows[0].Cells[0].Text = "No Record Found";
}
这篇关于如何显示“未找到记录”?在GridView asp.net中的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文