熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

當Gridview沒有數據 顯示表頭

2022-06-13   來源: .NET編程 

  在開發的時候很多時候都要用到GridView但是當GridView沒有數據時GridView就顯示不出來很難看正好最近做項目用到此方法就把代碼貼出來供大家學習及自己以後備用方法很簡單就是在GridView套用一個Table

  特別要注意此處<td colspan=> 沒有相關數據 </td>  colspan=是批GridView有多少列

  代碼

   <asp:GridView ID=grvStudentInfo runat=server CssClass=listgrid AutoGenerateColumns=False

                                       AllowSorting=True DataKeyNames=ID

                                       OnRowDeleting=grvStudentInfo_RowDeleting

                                       onrowdatabound=grvStudentInfo_RowDataBound>

                                       <EmptyDataTemplate>

                                           <table >

                                               <tr>

                                                   <th >

                                                       學生姓名

                                                   </th>

                                                   <th>

                                                       學號

                                                   </th>

                                                   <th>

                                                       刪除

                                                   </th>

                                               </tr>

                                               <tr align=center>

                                                   <td colspan=>

                                                       沒有相關數據

                                                   </td>

                                               </tr>

                                           </table>

                                       </EmptyDataTemplate>

                                       <Columns>

                                           <asp:BoundField DataField=StudentName HeaderText=學生姓名 />

                                           <asp:BoundField DataField=DetermineStuNo HeaderText=學號 />

                                           <asp:CommandField HeaderText=刪除 ShowDeleteButton=True />

                                       </Columns>

                                   </asp:GridView>

  出處


From:http://tw.wingwit.com/Article/program/net/201311/13740.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.