今天上网找了好久,用了个笨方法,css来实现,据说VS 2005 dataview就可以,可惜小弟还苦苦使用vs 2003
现在把我的方法分享下
第一步:添加datagrid的itembound事件
选择需要冻结列的css样式
//
冻结前7列
e.Item.Cells[ 0 ].CssClass = " locked " ;
e.Item.Cells[ 1 ].CssClass = " locked " ;
e.Item.Cells[ 2 ].CssClass = " locked " ;
e.Item.Cells[ 3 ].CssClass = " locked " ;
e.Item.Cells[ 4 ].CssClass = " locked " ;
e.Item.Cells[ 5 ].CssClass = " locked " ;
e.Item.Cells[ 6 ].CssClass = " locked " ;
e.Item.Cells[ 0 ].CssClass = " locked " ;
e.Item.Cells[ 1 ].CssClass = " locked " ;
e.Item.Cells[ 2 ].CssClass = " locked " ;
e.Item.Cells[ 3 ].CssClass = " locked " ;
e.Item.Cells[ 4 ].CssClass = " locked " ;
e.Item.Cells[ 5 ].CssClass = " locked " ;
e.Item.Cells[ 6 ].CssClass = " locked " ;
第二步 :将datagrid放在一个固定列宽的Div中
<
DIV
id
="div-datagrid"
>
< asp:datagrid id ="myDataGrid" runat ="server" AutoGenerateColumns ="False" UseAccessibleHeader ="True" >
< AlternatingItemStyle CssClass ="GridItem" ></ AlternatingItemStyle >
< ItemStyle CssClass ="GridItem" ></ ItemStyle >
< HeaderStyle CssClass ="GridHeader" ></ HeaderStyle >
< Columns >
< asp:TemplateColumn HeaderText ="客户名称" >
< HeaderStyle ForeColor ="Black" ></ HeaderStyle >
< ItemTemplate
< asp:datagrid id ="myDataGrid" runat ="server" AutoGenerateColumns ="False" UseAccessibleHeader ="True" >
< AlternatingItemStyle CssClass ="GridItem" ></ AlternatingItemStyle >
< ItemStyle CssClass ="GridItem" ></ ItemStyle >
< HeaderStyle CssClass ="GridHeader" ></ HeaderStyle >
< Columns >
< asp:TemplateColumn HeaderText ="客户名称" >
< HeaderStyle ForeColor ="Black" ></ HeaderStyle >
< ItemTemplate