日期:2014-05-18  浏览次数:20434 次

怎样在DataGrid中设置按钮列的样式
我有一个DataGrid,增加了两个按钮列,编辑更新和删除,但页面上按钮显示的样式不能设定,不能为这两个按钮列设置cssclass,

我使用了这个样式来定义:
.DataGridButton   input{
background-image   :   url(button.gif);
font-size:9pt;
font-family:Verdana;
height   :   20px;
width:55px;
border-width   :   0;
}
但编辑时,其他列的文本框也都加上了那个背景图片,查css帮助文档,发现有个方法:
-----------------------
Attribute   Selectors 版本:CSS2    兼容性:无
语法:
E   [   attr   ]   {   sRules   }  
E   [   attr   =   value   ]   {   sRules   }  
E   [   attr   ~=   value   ]   {   sRules   }  
E   [   attr   |=   value   ]   {   sRules   }  
说明:
属性选择符。  
选择具有   attr   属性的   E  
选择具有   attr   属性且属性值等于   value   的   E  
选择具有   attr   属性且属性值为一用空格分隔的字词列表,其中一个等于   value   的   E   。这里的   value   不能包含空格  
选择具有   attr   属性且属性值为一用连字符分隔的字词列表,由   value   开始的   E  
示例:
h[title]   {   color:   blue;   }  
/*   所有具有title属性的h对象   */  
 
span[class=demo]   {   color:   red;   }  
 
div[speed= "fast "][dorun= "no "]   {   color:   red;   }  
 
a[rel~= "copyright "]   {   color:black;   }  

-----------------------
但我写成下面这样也不能改变按钮的样式:
.DataGridButton   input[type=submit]{
background-image   :   url(button.gif);
font-size:9pt;
font-family:Verdana;
height   :   20px;
width:55px;
border-width   :   0;
}

有没有解决办法啊?

------解决方案--------------------
使用模板列:
<asp:TemplateColumn HeaderText= "Customer ">
<HeaderStyle Font-Size= "XX-Small " Font-Names= "Arial " Wrap= "False " HorizontalAlign= "Center "> </HeaderStyle>
<ItemStyle Font-Size= "XX-Small " Font-Names= "Arial " Wrap= "False " HorizontalAlign= "Center "> </ItemStyle>
<ItemTemplate>
<asp:LinkButton id= "lnkEdit " runat= "server " Font-Names= "Arial " Font-Size= "XX-Small " cssClass= ' '> Edit </asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
------解决方案--------------------
动态绑定给每个按钮加属性class
------解决方案--------------------
刚看了一下
ItemStyle 也是可以增加 CssClass 的