开发者

How To Freeze Columns in GridView

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.


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

  • Download from Codeplex.com.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜