private void BindData()
{
DataTable dt = DAO.RunSQLReturnDt(this.getsql());
int dtcount = dt.Rows.Count;
if (dtcount == )
{
dt.Rows.Add(dt.NewRow());
}
DataView dv = dt.DefaultView;
//对用于分页的类的引用
PagedDataSource pds = new PagedDataSource();
pds.DataSource = dv;//设置数据源(DataTable类型)
pds.AllowPaging = true;
//每页显示的行数
pds.PageSize = ;
AspNetPager1.RecordCount = dv.Count;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - ;
pds.PageSize = AspNetPager1.PageSize;
GridView1.DataSource = pds;
GridView1.DataBind();
if (dtcount <= )
{
int colnumcount = dt.Columns.Count;
GridView1.Rows[].Cells.Clear();
GridView1.Rows[].Cells.Add(new TableCell());
GridView1.Rows[].Cells[].ColumnSpan = colnumcount;
GridView1.Rows[].Cells[].Text = "没有相关记录";
GridView1.Rows[].Cells[].Style.Add("color", "red");
} }

页面正常显示

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="tablelist" GridLines="None" DataKeyNames="C_ID" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="C_AppNum" HeaderText="入库编号" SortExpression="C_AppNum">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField> <asp:BoundField DataField="C_AppDate" HeaderText="申请时间" SortExpression="C_AppDate">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="申请部门">
<ItemTemplate>
<%# XC.Depart.GetDepartName(Eval("C_AppDepartID").ToString()) %>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderText="申请人">
<ItemTemplate>
<%# XC.User.GetUserName(Eval("C_AppUserID").ToString())%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="C_Status" HeaderText="状态" SortExpression="C_Status">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="C_AuditState" HeaderText="审核状态" SortExpression="C_AuditState">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField> </Columns>
<HeaderStyle HorizontalAlign="center" />
</asp:GridView>

效果

GridView 无数据时,绑定提示-LMLPHP

05-11 17:39