首页 > 学院 > 开发设计 > 正文

GridView无数据时,绑定提示

2019-11-14 14:32:52
字体:
来源:转载
供稿:网友
 1  PRivate void BindData() 2     { 3         DataTable dt = DAO.RunSQLReturnDt(this.getsql()); 4         int dtcount = dt.Rows.Count; 5         if (dtcount == 0) 6         { 7             dt.Rows.Add(dt.NewRow()); 8         }  9         DataView dv = dt.DefaultView;10         //对用于分页的类的引用11         PagedDataSource pds = new PagedDataSource();12         pds.DataSource = dv;//设置数据源(DataTable类型)13         pds.AllowPaging = true;14         //每页显示的行数15         pds.PageSize = 20;16         aspNetPager1.RecordCount = dv.Count;17         pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;18         pds.PageSize = AspNetPager1.PageSize;19         GridView1.DataSource = pds;20         GridView1.DataBind();21         if (dtcount <= 0)22         {23             int colnumcount = dt.Columns.Count;24             GridView1.Rows[0].Cells.Clear();25             GridView1.Rows[0].Cells.Add(new TableCell());26             GridView1.Rows[0].Cells[0].ColumnSpan = colnumcount;27             GridView1.Rows[0].Cells[0].Text = "没有相关记录";28             GridView1.Rows[0].Cells[0].Style.Add("color", "red");29         }30 31 32     }

页面正常显示

 1 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CSSClass="tablelist" GridLines="None" DataKeyNames="C_ID" OnRowDataBound="GridView1_RowDataBound"> 2                     <Columns> 3                         <asp:BoundField DataField="C_AppNum" HeaderText="入库编号" SortExpression="C_AppNum"> 4                             <ItemStyle HorizontalAlign="Center" /> 5                         </asp:BoundField> 6  7  8                         <asp:BoundField DataField="C_AppDate" HeaderText="申请时间" SortExpression="C_AppDate"> 9                             <ItemStyle HorizontalAlign="Center" />10                         </asp:BoundField>11                         <asp:TemplateField HeaderText="申请部门">12                             <ItemTemplate>13                           <%# XC.Depart.GetDepartName(Eval("C_AppDepartID").ToString()) %>14                             </ItemTemplate>15                             <ItemStyle HorizontalAlign="Center" />16                         </asp:TemplateField>17                         <asp:TemplateField HeaderText="申请人">18                             <ItemTemplate>19                                 <%# XC.User.GetUserName(Eval("C_AppUserID").ToString())%>20                             </ItemTemplate>21                             <ItemStyle HorizontalAlign="Center" />22                         </asp:TemplateField>23                         <asp:BoundField DataField="C_Status" HeaderText="状态" SortExpression="C_Status">24                             <ItemStyle HorizontalAlign="Center" />25                         </asp:BoundField>26                         <asp:BoundField DataField="C_AuditState" HeaderText="审核状态" SortExpression="C_AuditState">27                             <ItemStyle HorizontalAlign="Center" />28                         </asp:BoundField>29                        30                     </Columns>31                     <HeaderStyle HorizontalAlign="center" />32                 </asp:GridView>

 

效果

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表