How To Freeze Columns in GridView

笑着哭i 提交于 2019-12-12 01:08:54

问题


I'm trying to freeze columns in gridview where grid has static height and all rows are rendered(no paging and scroll var is visible). I only managed to add scroll through content by overflow property,but this time all columns are scrolling as well.My task is to freeze columns while maintaining column width.

Let this be my grid

<div style="height:200px;overflow:auto;">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        UseAccessibleHeader="true or false">
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Name" />
            <asp:BoundField DataField="Surname" HeaderText="Surname" />
        </Columns>
    </asp:GridView>
</div>

and this is code view

 public class Person
 {
     public String Name { get; set; }
     public String Surname { get; set; }
 }

->On Page Load

    List<Person> lst = new List<Person>();

    lst.Add(new Person() { Name = "A", Surname = "A1" });
    lst.Add(new Person() { Name = "B", Surname = "B1" });
    lst.Add(new Person() { Name = "C", Surname = "C1" });
    lst.Add(new Person() { Name = "D", Surname = "D1" });
    lst.Add(new Person() { Name = "E", Surname = "E1" });
    lst.Add(new Person() { Name = "F", Surname = "F1" });
    lst.Add(new Person() { Name = "G", Surname = "G1" });
    lst.Add(new Person() { Name = "H", Surname = "H1" });
    lst.Add(new Person() { Name = "I", Surname = "I1" });
    lst.Add(new Person() { Name = "J", Surname = "J1" });
    lst.Add(new Person() { Name = "K", Surname = "K1" });

    GridView1.DataSource = lst;
    GridView1.DataBind();

How can i achieve this with minimum effort of coding or styling?
Note:Rendered browser is IE only.


回答1:


You could use the Ideasparks CoolGridView instead. It works fine for me and is free.

  • Download from Codeplex.com.


来源:https://stackoverflow.com/questions/5093635/how-to-freeze-columns-in-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!