日期:2014-05-20  浏览次数:20442 次

GridView控件数据为空时,不能正常显示的问题
我已经设置了 <EmptyDataTemplate> ,可是数据为空时,仍然不能正常显示表头。

为此,我在网上找了很多资料,按照其中的方法做了测试程序,在测试程序中,数据为空时是正常的,但是只要迁移到项目中,就不成功,代码如下:

……
<asp:GridView   ID= "GridView1 "   runat= "server "   cssselectorclass= "PrettyGridView "   SkinID= "SampleGridView "                                                                         AllowPaging= "True "   AllowSorting= "True "   OnRowDeleting= "GridView1_RowDeleting "   OnSelectedIndexChanged= "GridView1_SelectedIndexChanged "                                                                         AutoGenerateColumns= "False "   DataKeyNames= "NeEngName "   OnDataBound= "GridView1_DataBound "                                                                         DataSourceID= "ObjectDataSource1 "   PageSize= "15 ">                                                                         <EmptyDataTemplate>
<table   cellpadding= "0 "   cellspacing= "0 "   summary= " ">
<thead>
<tr>                                         <th   scope= "col "> 中文名 </th>
……                                         </tr>
</thead>
</EmptyDataTemplate>
<Columns>
<asp:TemplateField   HeaderText= "中文名 ">
<EditItemTemplate>
<asp:TextBox   ID= "TextBox1 "   runat= "server "   Text= ' <%#   Bind( "NeChsName ")   %> '> </asp:TextBox>
</EditItemTemplate>
……
<ItemTemplate>
<asp:Label   ID= "Label1 "   runat= "server "   Text= ' <%#   Bind( "NeChsName ")   %> '> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField   HeaderText= "修改 ">
<ItemTemplate>
<asp:LinkButton   ID= "NeSelect "   Text= "修改 "   CommandName= "Select "   Width= "40px "   runat= "server "   />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField   HeaderText= "删除 ">
<ItemTemplate>
<asp:LinkButton   ID= "NeDelete "   runat= "server "   CausesValidation= "False "   CommandName= "Delete "   Width= "40px "   Text= "删除 "   OnClientClick= "return   confirm( '确认要删除此行信息吗? ') "> </asp:LinkButton>