如何为Gridview单元格的不同边框赋予特定的边框样式 [英] How to give Particular Border Styles to Different Borders Of a Gridview Cell
问题描述
你好朋友
我有gridview,它是动态创建的,并在单击按钮时将其传递到Excel中...
使用ItemBound(Like Rowbound)事件,我要将特定单元格的边框样式设置为None ...实际上,我需要删除特定单元格的边框Left,Top和Bottom部分,我不想删除右侧的Border.这样做吗?
请给我一些提示....
Hi friends
I have gridview which I am dynamically creating and Passing Its into Excel on button click...
Using ItemBound(Like Rowbound) event I am setting particular cell Border Style into None... actally I need to Remove the Border of particular cells Left,Top and Bottom part I dont want to remove the Border on Right side Is there any way to do this?
Please give me some Tips.......
推荐答案
好吧,rowstyle定义了tr的样式,但我需要为td设置样式.我知道如何为td指定类,但是我必须为列中的every节点指定类.
我能够在CSS文件中解决此问题.我首先为RowStyle和AlternatingRowStyle指定了一个CSS类.然后在CSS中创建了这样的新样式
Well, the rowstyle defines the style for the tr but I need to style the td. I know how do specify the class for the td but I have to do it for everty node in columns.
I was able to solve this issue in my css file. I first specified a css class for RowStyle and AlternatingRowStyle. Then in the css I created a new style like this
.GridViewRowStyle td, .GridViewAlternatingRowStyle td
{
/* style for the td*/
}
我想要这样做的原因是因为asp.net呈现GridView的方式,在所有浏览器中看起来都不一样.因此,我想使用纯CSS对其进行外观设置,以便在所有浏览器中看起来都一样,现在也可以了.下面是css代码和如果其他任何人遇到此问题时使用的外观代码.
The reason I wanted to this was because the way asp.net renders the GridView, it does not look the same in all browsers. So I wanted to skin it using pure css so it would look the same in all browsers and now it does. Below is the css code and the skin code that I used if anyone else is having this issue.
.GridViewStyle
{
border-right: 2px solid #A7A6AA;
border-bottom: 2px solid #A7A6AA;
border-left: 2px solid white;
border-top: 2px solid white;
padding: 4px;
}
.GridViewStyle a
{
color: #FFFFFF;
}
.GridViewHeaderStyle th
{
border-left: 1px solid #EBE9ED;
border-right: 1px solid #EBE9ED;
}
.GridViewHeaderStyle
{
background-color: #5D7B9D;
font-weight: bold;
color: White;
}
.GridViewFooterStyle
{
background-color: #5D7B9D;
font-weight: bold;
color: White;
}
.GridViewRowStyle
{
background-color: #F7F6F3;
color: #333333;
}
.GridViewAlternatingRowStyle
{
background-color: #FFFFFF;
color: #284775;
}
.GridViewRowStyle td, .GridViewAlternatingRowStyle td
{
border: 1px solid #EBE9ED;
}
.GridViewSelectedRowStyle
{
background-color: #E2DED6;
font-weight: bold;
color: #333333;
}
.GridViewPagerStyle
{
background-color: #284775;
color: #FFFFFF;
}
.GridViewPagerStyle table /* to center the paging links*/
{
margin: 0 auto 0 auto;
}
皮肤文件:
Skin file:
<asp:GridView CssClass="GridViewStyle" runat="server" >
<FooterStyle CssClass="GridViewFooterStyle" />
<RowStyle CssClass="GridViewRowStyle" />
<SelectedRowStyle CssClass="GridViewSelectedRowStyle" />
<PagerStyle CssClass="GridViewPagerStyle" />
<AlternatingRowStyle CssClass="GridViewAlternatingRowStyle" />
<HeaderStyle CssClass="GridViewHeaderStyle" />
</asp:GridView>
在Item_bound事件中,我们可以通过这种方式为特定单元格提供样式
In Item_bound event we can give styles to particular cells in this way
e.Item.Cells[1].Style.Add("border-right-color","black");
e.Item.Cells[1].Style.Add("border-top-color", "white");
e.Item.Cells[1].Style.Add("border-bottom-color", "white");
或者我们可以在aspx.cs页面中调用CSS类
这样
or we can call css class inside aspx.cs page
in this way
e.Item.CssClass = "GridViewStyle";
但是css类对我不起作用,但是使用第一种方法可以解决我的问题.
but css class is not working for me but using first method I fix my problem.
这篇关于如何为Gridview单元格的不同边框赋予特定的边框样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!