C# 如何将CSS样式应用于GridView中BoundField内的块/标记
我有一个gridview:C# 如何将CSS样式应用于GridView中BoundField内的块/标记,c#,html,css,asp.net,vb.net,C#,Html,Css,Asp.net,Vb.net,我有一个gridview: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style> .GridViewCell { display:inline-block; width:200; } </style> </h
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style> .GridViewCell
{
display:inline-block;
width:200; } </style>
</head>
<body>
<div>
<asp:GridView ID="gvExportList" AutoGenerateColumns="false" AllowPaging="false" AllowSorting="false" runat="server" HeaderStyle-BackColor="LightGray">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID #" DataFormatString=" {0}" />
<asp:BoundField DataField="Date" HeaderText="Date" DataFormatString="{0:MM/dd/yyyy}" />
<asp:BoundField DataField="Text" HeaderText="Text" />
</Columns>
</asp:GridView>
</div>
</body>
</html>
使用ItemStyle CSS
将CSS样式应用于整个字符串,而不是我想要的样式:
<ItemStyle CssClass="GridViewCell" />
输出:
也许只是&tab;会有帮助吗 或者,如果您希望每个单词在元素中隔开。 下面是一个用css/html实现的示例 css html
同侧耳
参考资料:您的最终HTML是什么样子的?asp.net为整个
gridview
或仅为文本字段生成的html…@Dekel?如果你只是指文本字段,它看起来就像我在上面最后展示的那样。asp.net生成html@Dekel我添加了HTML代码。您只添加了
标记,而不是输出。。。
<ItemStyle CssClass="GridViewCell" />
div{
background-color:gold;
text-align:justify;
}
span{
background-color:red;
width:100%;
height:1em;
display:inline-block;
}
<div>
Lorem ipsum sit dolor
<span> </span>
</div>