gridview是 asp.net2.0的新控件,在vs2005中可以选取自动套用格式来确定他的风格,但是发现他的girdline(网格线)属性,只能设置在什么方向存在(没有,横,纵,横纵都有),而不能设置格式,比如我想设置网格线为虚线,但是无法设置。
这个时候,进入columns集合,如果内容已经绑定,在其中已经出现相应的列,如该例子id,content然后设置它们的itemstyle中的cssclass属性为class1,其中class1件下面的文件,其中gridview1的数据源只是两个字段,id和content两个字段
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " Default2.aspx.cs " Inherits = " Default2 " %>
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >
< style >
.class1
{
border-top-style: none;
border-bottom: red 1px dashed;
}
</ style >
< title > gridview风格 </ title >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
& nbsp;
< asp:GridView ID = " GridView1 " runat = " server " Height = " 164px " Width = " 575px " AutoGenerateColumns = " False " DataKeyNames = " id " DataSourceID = " AccessDataSource1 " GridLines = " None " >
< Columns >
< asp:BoundField DataField = " id " InsertVisible = " False " ReadOnly = " True "
SortExpression = " id " >
< ItemStyle CssClass = " class1 " />
</ asp:BoundField >
< asp:BoundField DataField = " content " SortExpression = " content " >
< ItemStyle CssClass = " class1 " />
</ asp:BoundField >
</ Columns >
</ asp:GridView >
< asp:AccessDataSource ID = " AccessDataSource1 " runat = " server " DataFile = " ~/Data/style.mdb "
SelectCommand = " SELECT id,content FROM [test] " ></ asp:AccessDataSource >
</ div >
</ form >
</ body >
</ html >
这个时候,进入columns集合,如果内容已经绑定,在其中已经出现相应的列,如该例子id,content然后设置它们的itemstyle中的cssclass属性为class1,其中class1件下面的文件,其中gridview1的数据源只是两个字段,id和content两个字段
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " Default2.aspx.cs " Inherits = " Default2 " %>
<! DOCTYPE html PUBLIC " -//W3C//DTD XHTML 1.0 Transitional//EN " " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >
< style >
.class1
{
border-top-style: none;
border-bottom: red 1px dashed;
}
</ style >
< title > gridview风格 </ title >
</ head >
< body >
< form id = " form1 " runat = " server " >
< div >
& nbsp;
< asp:GridView ID = " GridView1 " runat = " server " Height = " 164px " Width = " 575px " AutoGenerateColumns = " False " DataKeyNames = " id " DataSourceID = " AccessDataSource1 " GridLines = " None " >
< Columns >
< asp:BoundField DataField = " id " InsertVisible = " False " ReadOnly = " True "
SortExpression = " id " >
< ItemStyle CssClass = " class1 " />
</ asp:BoundField >
< asp:BoundField DataField = " content " SortExpression = " content " >
< ItemStyle CssClass = " class1 " />
</ asp:BoundField >
</ Columns >
</ asp:GridView >
< asp:AccessDataSource ID = " AccessDataSource1 " runat = " server " DataFile = " ~/Data/style.mdb "
SelectCommand = " SELECT id,content FROM [test] " ></ asp:AccessDataSource >
</ div >
</ form >
</ body >
</ html >
运行效果如下!
只能曲线救国,达到这样的目的,gridview没有这个属性,当然还可以根据css设置其他属性,就根据大家的需要了
来源:http://blog.csdn.net/wing2002li2/archive/2006/10/28/1354576.aspx