gridview 固定表头,滚动在里面的,比前面的写的好看,css实现
这个grid写的有点乱了,主要的是外面的div,和里面的grid关系不是很大
 <div id="div-gridview" style="height:520px;">
<div id="div-gridview" style="height:520px;">
 <asp:GridView ID="GridView1" runat="server" SkinID="AllowPage"  AllowPaging="false" Width="98%"
                                <asp:GridView ID="GridView1" runat="server" SkinID="AllowPage"  AllowPaging="false" Width="98%"
 OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" AutoGenerateColumns="False"
                                 OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" AutoGenerateColumns="False"
 DataKeyNames="CountyId" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound"
                                  DataKeyNames="CountyId" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound" 
 OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand">
                                  OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand">
 <Columns>
                                    <Columns>
 <asp:TemplateField>
                                        <asp:TemplateField>
 <HeaderTemplate>
                                        <HeaderTemplate>
 <asp:CheckBox ID="checkboxAll" runat="server" Text="全选" OnCheckedChanged="CheckAll" AutoPostBack="true" />
                                            <asp:CheckBox ID="checkboxAll" runat="server" Text="全选" OnCheckedChanged="CheckAll" AutoPostBack="true" />
 </HeaderTemplate>
                                        </HeaderTemplate>
 <ItemStyle HorizontalAlign="Left" Width="50px" />
                                        <ItemStyle HorizontalAlign="Left" Width="50px" />
 <HeaderStyle HorizontalAlign="Left" Width="50px" />
                                        <HeaderStyle HorizontalAlign="Left" Width="50px" />
 <ItemTemplate>
                                        <ItemTemplate>
 <asp:CheckBox ID="checkboxDan" runat="server" />
                                            <asp:CheckBox ID="checkboxDan" runat="server" />
 <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("CountyId") %>' />
                                            <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("CountyId") %>' />
 <asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Eval("IntId") %>' />
                                                <asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Eval("IntId") %>' />
 <asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Eval("BtsName") %>' />
                                                <asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Eval("BtsName") %>' />
 <asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Eval("Lac") %>' />
                                                <asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Eval("Lac") %>' />
 <asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Eval("CellId") %>' />
                                                <asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Eval("CellId") %>' />
 <asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Eval("CellDesc") %>' />
                                                <asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Eval("CellDesc") %>' />
 </ItemTemplate>
                                        </ItemTemplate>
 </asp:TemplateField>
                                        </asp:TemplateField>
 <asp:BoundField DataField="CountyName" HeaderText="乡镇名">
                                        <asp:BoundField DataField="CountyName" HeaderText="乡镇名">
 <ItemStyle Wrap="True" />
                                            <ItemStyle Wrap="True" />
 <HeaderStyle Wrap="False" />
                                            <HeaderStyle Wrap="False" />
 </asp:BoundField>
                                        </asp:BoundField>
 <asp:ButtonField CommandName="see" HeaderText="查看小区" Text="点击查看" />
                                        <asp:ButtonField CommandName="see" HeaderText="查看小区" Text="点击查看" />
 <asp:CommandField ShowEditButton="True" EditText="编辑" UpdateText="更新" CancelText="取消">
                                        <asp:CommandField ShowEditButton="True" EditText="编辑" UpdateText="更新" CancelText="取消">
 <HeaderStyle Wrap="False" />
                                            <HeaderStyle Wrap="False" />
 <ItemStyle Wrap="False" />
                                            <ItemStyle Wrap="False" />
 </asp:CommandField>
                                        </asp:CommandField>
 <asp:CommandField ShowDeleteButton="True" DeleteText="删除">
                                        <asp:CommandField ShowDeleteButton="True" DeleteText="删除">
 <HeaderStyle Wrap="False" />
                                            <HeaderStyle Wrap="False" />
 <ItemStyle Wrap="False" />
                                            <ItemStyle Wrap="False" />
 </asp:CommandField>
                                        </asp:CommandField>
 </Columns>
                                    </Columns>
 <PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                <PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" />
 </asp:GridView></div>
                                </asp:GridView></div>
再加上这个.css就ok了
 /* Div container to wrap the datagrid */
/* Div container to wrap the datagrid */
 div#div-gridview {
div#div-gridview {
 width: 100%;
width: 100%;
 height: 160px;
height: 160px;
 overflow: auto;
overflow: auto;
 }
}

 div#div-gridview1
div#div-gridview1 
 {
{
 width: 420px;
    width: 420px;
 height: 200px;
height: 200px;
 overflow: auto;
overflow: auto;
 }
}

 div#div-gridview2
div#div-gridview2 
 {
{
 width: 420px;
    width: 420px;
 height: 200px;
height: 200px;
 overflow: auto;
overflow: auto;
 }
}

 div#div-gridview3
div#div-gridview3 
 {
{
 height: 0px;
height: 0px;
 overflow: auto;
overflow: auto;
 }
}
 /* Locks the left column */
/* Locks the left column */
 td.locked, th.locked {
td.locked, th.locked {

 position:relative;
    position:relative;

 left: expression(document.getElementById("div-gridview3").scrollLeft-2); /*IE5+ only*/
    left: expression(document.getElementById("div-gridview3").scrollLeft-2); /*IE5+ only*/
 }
} 

 /* Locks table header */
/* Locks table header */
 th {
th {

 position:relative;
    position:relative;
 top:expression(document.getElementById("div-gridview3").scrollTop-1);  /*IE5+ only*/
    top:expression(document.getElementById("div-gridview3").scrollTop-1);  /*IE5+ only*/
 z-index: 10;
    z-index: 10;
 }
}

 /* Keeps the header as the top most item. Important for top left item*/
/* Keeps the header as the top most item. Important for top left item*/
 th.locked {z-index: 99;}
th.locked {z-index: 99;}

 /* DataGrid Item and AlternatingItem Style
/* DataGrid Item and AlternatingItem Style
 .GridRow {font-size: 10pt; color: black; font-family: Arial; background-color:#ffffff; height:35px;}
.GridRow {font-size: 10pt; color: black; font-family: Arial; background-color:#ffffff; height:35px;}
 .GridAltRow {font-size: 10pt; color: black; font-family: Arial; background-color:#eeeeee; height:35px;}
.GridAltRow {font-size: 10pt; color: black; font-family: Arial; background-color:#eeeeee; height:35px;}


 */
*/


 其实里面只要有
其实里面只要有
div#div-gridview {
width: 100%;
height: 160px;
overflow: auto;
}
就可以了,但是为什么还有其他3个呢,因为有的时候页面要求多个gridview,这个时候你只写一个,其他的也会跟着动起来,所以写一个别的名,这样就不影响了
 <div id="div-gridview" style="height:520px;">
<div id="div-gridview" style="height:520px;"> <asp:GridView ID="GridView1" runat="server" SkinID="AllowPage"  AllowPaging="false" Width="98%"
                                <asp:GridView ID="GridView1" runat="server" SkinID="AllowPage"  AllowPaging="false" Width="98%" OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" AutoGenerateColumns="False"
                                 OnPageIndexChanging="GridView1_PageIndexChanging" OnRowDeleting="GridView1_RowDeleting" AutoGenerateColumns="False" DataKeyNames="CountyId" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound"
                                  DataKeyNames="CountyId" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDataBound="GridView1_RowDataBound"  OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand">
                                  OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCommand="GridView1_RowCommand"> <Columns>
                                    <Columns> <asp:TemplateField>
                                        <asp:TemplateField> <HeaderTemplate>
                                        <HeaderTemplate> <asp:CheckBox ID="checkboxAll" runat="server" Text="全选" OnCheckedChanged="CheckAll" AutoPostBack="true" />
                                            <asp:CheckBox ID="checkboxAll" runat="server" Text="全选" OnCheckedChanged="CheckAll" AutoPostBack="true" /> </HeaderTemplate>
                                        </HeaderTemplate> <ItemStyle HorizontalAlign="Left" Width="50px" />
                                        <ItemStyle HorizontalAlign="Left" Width="50px" /> <HeaderStyle HorizontalAlign="Left" Width="50px" />
                                        <HeaderStyle HorizontalAlign="Left" Width="50px" /> <ItemTemplate>
                                        <ItemTemplate> <asp:CheckBox ID="checkboxDan" runat="server" />
                                            <asp:CheckBox ID="checkboxDan" runat="server" /> <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("CountyId") %>' />
                                            <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("CountyId") %>' /> <asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Eval("IntId") %>' />
                                                <asp:HiddenField ID="HiddenField2" runat="server" Value='<%# Eval("IntId") %>' /> <asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Eval("BtsName") %>' />
                                                <asp:HiddenField ID="HiddenField3" runat="server" Value='<%# Eval("BtsName") %>' /> <asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Eval("Lac") %>' />
                                                <asp:HiddenField ID="HiddenField4" runat="server" Value='<%# Eval("Lac") %>' /> <asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Eval("CellId") %>' />
                                                <asp:HiddenField ID="HiddenField5" runat="server" Value='<%# Eval("CellId") %>' /> <asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Eval("CellDesc") %>' />
                                                <asp:HiddenField ID="HiddenField6" runat="server" Value='<%# Eval("CellDesc") %>' /> </ItemTemplate>
                                        </ItemTemplate> </asp:TemplateField>
                                        </asp:TemplateField> <asp:BoundField DataField="CountyName" HeaderText="乡镇名">
                                        <asp:BoundField DataField="CountyName" HeaderText="乡镇名"> <ItemStyle Wrap="True" />
                                            <ItemStyle Wrap="True" /> <HeaderStyle Wrap="False" />
                                            <HeaderStyle Wrap="False" /> </asp:BoundField>
                                        </asp:BoundField> <asp:ButtonField CommandName="see" HeaderText="查看小区" Text="点击查看" />
                                        <asp:ButtonField CommandName="see" HeaderText="查看小区" Text="点击查看" /> <asp:CommandField ShowEditButton="True" EditText="编辑" UpdateText="更新" CancelText="取消">
                                        <asp:CommandField ShowEditButton="True" EditText="编辑" UpdateText="更新" CancelText="取消"> <HeaderStyle Wrap="False" />
                                            <HeaderStyle Wrap="False" /> <ItemStyle Wrap="False" />
                                            <ItemStyle Wrap="False" /> </asp:CommandField>
                                        </asp:CommandField> <asp:CommandField ShowDeleteButton="True" DeleteText="删除">
                                        <asp:CommandField ShowDeleteButton="True" DeleteText="删除"> <HeaderStyle Wrap="False" />
                                            <HeaderStyle Wrap="False" /> <ItemStyle Wrap="False" />
                                            <ItemStyle Wrap="False" /> </asp:CommandField>
                                        </asp:CommandField> </Columns>
                                    </Columns> <PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                                <PagerStyle HorizontalAlign="Center" VerticalAlign="Middle" /> </asp:GridView></div>
                                </asp:GridView></div>再加上这个.css就ok了
 /* Div container to wrap the datagrid */
/* Div container to wrap the datagrid */ div#div-gridview {
div#div-gridview { width: 100%;
width: 100%; height: 160px;
height: 160px; overflow: auto;
overflow: auto; }
}
 div#div-gridview1
div#div-gridview1  {
{ width: 420px;
    width: 420px; height: 200px;
height: 200px; overflow: auto;
overflow: auto; }
}
 div#div-gridview2
div#div-gridview2  {
{ width: 420px;
    width: 420px; height: 200px;
height: 200px; overflow: auto;
overflow: auto; }
}
 div#div-gridview3
div#div-gridview3  {
{ height: 0px;
height: 0px; overflow: auto;
overflow: auto; }
} /* Locks the left column */
/* Locks the left column */ td.locked, th.locked {
td.locked, th.locked {
 position:relative;
    position:relative;
 left: expression(document.getElementById("div-gridview3").scrollLeft-2); /*IE5+ only*/
    left: expression(document.getElementById("div-gridview3").scrollLeft-2); /*IE5+ only*/ }
} 
 /* Locks table header */
/* Locks table header */ th {
th {
 position:relative;
    position:relative; top:expression(document.getElementById("div-gridview3").scrollTop-1);  /*IE5+ only*/
    top:expression(document.getElementById("div-gridview3").scrollTop-1);  /*IE5+ only*/ z-index: 10;
    z-index: 10; }
}
 /* Keeps the header as the top most item. Important for top left item*/
/* Keeps the header as the top most item. Important for top left item*/ th.locked {z-index: 99;}
th.locked {z-index: 99;}
 /* DataGrid Item and AlternatingItem Style
/* DataGrid Item and AlternatingItem Style .GridRow {font-size: 10pt; color: black; font-family: Arial; background-color:#ffffff; height:35px;}
.GridRow {font-size: 10pt; color: black; font-family: Arial; background-color:#ffffff; height:35px;} .GridAltRow {font-size: 10pt; color: black; font-family: Arial; background-color:#eeeeee; height:35px;}
.GridAltRow {font-size: 10pt; color: black; font-family: Arial; background-color:#eeeeee; height:35px;}

 */
*/


div#div-gridview {
width: 100%;
height: 160px;
overflow: auto;
}
就可以了,但是为什么还有其他3个呢,因为有的时候页面要求多个gridview,这个时候你只写一个,其他的也会跟着动起来,所以写一个别的名,这样就不影响了
 
                    
                
 }
} left
    left 
                
            
         
 浙公网安备 33010602011771号
浙公网安备 33010602011771号