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" SortExpressi开发者_开发百科on="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>
What happens if you add HorizontalAlign="Center" to the EmptyDataRowStyle tag? Also, are you using skins at all?
Your selector in the css code should be:
tr.mycentertext td { text-align: center;font-size: 12px;font-family: Verdana; }
All you have to do is add to the gridview a CssClass="myGrid
and in that "myGrid" style you should add margin: 0 auto
and that will align the emptydata message to the center.
精彩评论