Click here to Skip to main content
16,017,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I need a gridview column to be freezed only on horizontal scroll and a normal behaviour on vertical scroll.

I applied the below style but it freezes the column on both horizontal and vertical scroll
C#
td.locked
{
    position: relative ;
    left: expression((this.parentElement.parentElement.parentElement.parentElement.scrollTop-2)+'px');
}

Can anyone pls help me out on this. I have searched a lot but the same style is posted everywhere.
Posted
Updated 19-Aug-13 0:35am
v2

1 solution

Put the grid view in one Div and set the div's class parameters as below
C#
.grid_wrapper
{
float:left;
width:80%;(put this as per your page settings and designs)
height:200px;(put this as per your page settings and designs)
overflow:scroll;
display:block;
}

C#
<div class="grid_wrapper">
<asp:GridView ID="ParentGridView" runat="server" DataSourceID="ParentSqlDataSource"
         AutoGenerateColumns="False" DataKeyNames="pub_id" OnRowEditing="ParentGridView_OnRowEditing">
         <Columns>
             <asp:TemplateField HeaderText="PublisherID">
                 <ItemTemplate>
                     <asp:Label ID="pubid_lbl" runat="Server" Text='<%# Eval("pub_id") %>' />
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="Name">
                 <ItemTemplate>
                     <asp:Label ID="name_lbl" runat="Server" Text='<%# Eval("pub_name") %>' />
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="City">
                 <ItemTemplate>
                     <asp:Label ID="city_lbl" runat="Server" Text='<%# Eval("city") %>' />
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="View">
                 <ItemTemplate>
                     <asp:Button ID="ViewChild_Button" runat="server" Text="+" CommandName="Edit" />
                 </ItemTemplate>
                 <EditItemTemplate>
                     <asp:Button ID="CancelChild_Button" runat="server" Text="-" CommandName="Cancel" />
                     <asp:GridView ID="ChildGridView" runat="server" AllowPaging="true" PageSize="4" AutoGenerateColumns="false"
                         DataSourceID="ChildSqlDataSource" OnRowEditing="ChildGridView_OnRowEditing">
                         <Columns>
 
                         </Columns>
                     </asp:GridView>
                 </EditItemTemplate>
             </asp:TemplateField>
         </Columns>
     </asp:GridView>
</div>
 
Share this answer
 
v4
Comments
komaliks 19-Aug-13 10:25am    
Thank you for the post. But my problem is not providing the scroll in the gridview.

I want the first column in the gridview to be fixed while scrolling horizontal. For example,Gridview has some 15 columns with 'Name' is the first column header name.

This 'Name column' disappers while we scroll horizontal and dont know for which Name the data row is for.

I need the Name column to scroll along with the horizontal scroll.

At the same, I do not want it to be scrolling when scroll vertical.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900