Gridview - 将标签“EmptyDataText”居中对齐; &所以它不是默认的页面左侧
我的 C# 程序中有一个 gridview 控件。基本上,有人输入电子邮件地址,然后数据显示在网格视图中,但如果在电子邮件地址中找不到数据,则会使用 EmptyDataText="no data available" 标签显示一条消息,但我似乎无法设置文本样式'没有可用数据”,因此它显示在页面的中心而不是默认的左侧。尽管 CSS 似乎确实有效,因为我可以更改字体大小和类型,但不能更改文本对齐:居中。
我尝试了许多不同的选项:
<EmptyDataRowStyle Font-Size="12px" text-align="center" />
问题是 text-align:center 不是有效的属性。
另一个选择是:
<EmptyDataRowStyle cssclass="mycentertext" />
然后我链接到我的 style.css 文件并放入其中:
.mycentertext {text-align: center;font-size: 12px;font-family: Verdana;}
再次,字体大小和字体类型发生变化,但仍然没有对齐。
请帮忙!
这是我的网格视图:
<asp:GridView ID="GridView1" Visible="false" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource" EmptyDataText="No data could be found for the email address" CellSpacing="3" CellPadding="4"
GridLines="None" ForeColor="#333333">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="EmailAddress" HeaderText="Email Address" SortExpression="EmailAddress">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="Address1" HeaderText="Address1" SortExpression="Address1">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="Address2" HeaderText="Address2" SortExpression="Address2">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="city" HeaderText="City" SortExpression="city">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<EmptyDataRowStyle cssclass="mycentertext" />
</asp:GridView>
I have a gridview control in my c# program. Basically someone enters an email address and the data is then shown in the gridview but if no data could be found with the email address, a message is displayed using the EmptyDataText="no data available" tag but I cannot seem to style the text 'no data available' so it appears in the centre of the page rather than the default left. Though the CSS does seem to be working as I can change the font size and type but not text-align:center.
I've tried a number of different options:
<EmptyDataRowStyle Font-Size="12px" text-align="center" />
The problem is the text-align:center is not a valid attribute.
Another option was:
<EmptyDataRowStyle cssclass="mycentertext" />
And then I link to my style.css file and place in that:
.mycentertext {text-align: center;font-size: 12px;font-family: Verdana;}
Again, the font size changes and the font type but still not aligned.
Please help!
This is my gridview:
<asp:GridView ID="GridView1" Visible="false" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
DataSourceID="SqlDataSource" EmptyDataText="No data could be found for the email address" CellSpacing="3" CellPadding="4"
GridLines="None" ForeColor="#333333">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="EmailAddress" HeaderText="Email Address" SortExpression="EmailAddress">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="Address1" HeaderText="Address1" SortExpression="Address1">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="Address2" HeaderText="Address2" SortExpression="Address2">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
<asp:BoundField DataField="city" HeaderText="City" SortExpression="city">
<ItemStyle Font-Names="Verdana" Font-Size="9pt" />
<HeaderStyle Font-Names="Verdana" Font-Size="10pt" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<EmptyDataRowStyle cssclass="mycentertext" />
</asp:GridView>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果将 HorizontalAlign="Center" 添加到 EmptyDataRowStyle 标记会发生什么情况?另外,你还用皮肤吗?
What happens if you add HorizontalAlign="Center" to the EmptyDataRowStyle tag? Also, are you using skins at all?
css 代码中的选择器应为:
tr.mycentertext td { text-align: center;font-size: 12px;font-family: Verdana; }
Your selector in the css code should be:
tr.mycentertext td { text-align: center;font-size: 12px;font-family: Verdana; }
您所要做的就是向 gridview 添加一个
CssClass="myGrid
,并在该“myGrid”样式中添加margin: 0 auto
,这将对齐空数据消息到中心。All you have to do is add to the gridview a
CssClass="myGrid
and in that "myGrid" style you should addmargin: 0 auto
and that will align the emptydata message to the center.