i need to build table data... mens data come in grid.. on the top of the table ther is is header line under the header line all data come in row.. now i have to develop when i scroll the data header will not scroll Head 1 head 2 head 3 this part not scroll (header need fix) a1 a2 a3 scroll b1 b2 b3 scroll c1 c2 c3 scroll d1 d2 d3 scroll e1 e2 e3 scroll in short i need Fixed header in ASP.NET DataGrid.
here is the code it not working in firefox as we as IE 8 i want to fix the heder <asp:Panel ID="Panel1" runat="server" ScrollBars="Both" Height="300" Width="100%"> <asp:GridView ID="grdsuspect" runat="server" AllowSorting="True" AutoGenerateColumns="False" CssClass="Grid" BorderColor="#DDDDDD" BorderStyle="Solid" BorderWidth="0px" CellPadding="3" DataKeyNames="crm_suspects_detail_id" EmptyDataText="No Data Found" GridLines="None" Height="1px" PageSize="13" Width="97%" UseAccessibleHeader="true"> <EmptyDataRowStyle BorderWidth="1px" CssClass="grdemptyitemstyle" ForeColor="Black" HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" /> <Columns> <asp:TemplateField> <HeaderTemplate> Date Input </HeaderTemplate> <ItemStyle BorderColor="#DDDDDD" BorderWidth="1px" CssClass="grditemstyle" HorizontalAlign="left" /> <HeaderStyle BorderColor="#DDDDDD" BorderWidth="1px" Font-Bold="False" HorizontalAlign="Left" Width="10%" /> <ItemTemplate> <asp:Label ID="lbldate" runat="server" CssClass='<%#IIf(DataBinder.Eval(Container.DataItem, "datdiff") >= DataBinder.Eval(Container.DataItem, "no_suspect_reg"), "grditemstylered", "grditemstyle")%>' Text='<%# Eval("created_date") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField> <HeaderTemplate> Company Name </HeaderTemplate> <ItemStyle BorderColor="#DDDDDD" BorderWidth="1px" CssClass="grditemstyle" HorizontalAlign="left" /> <HeaderStyle BorderColor="#DDDDDD" BorderWidth="1px" Font-Bold="False" HorizontalAlign="Left" Width="25%" /> <ItemTemplate> <asp:LinkButton ID="lnksuscontectEdit" runat="server" CausesValidation="false" CommandArgument='Edit' CommandName="Edit" CssClass="grditemstyle" Text='<%# Eval("company_name") %>'></asp:LinkButton> </ItemTemplate> </asp:TemplateField> <asp:BoundField DataField="contactname" HeaderText="Contact Name"> <ItemStyle BorderColor="#DDDDDD" BorderWidth="1px" CssClass="grditemstyle" Font-Bold="False" HorizontalAlign="Left" VerticalAlign="Top" /> <HeaderStyle BorderColor="#DDDDDD" BorderWidth="1px" Font-Bold="False" HorizontalAlign="Left" Width="15%" /> </asp:BoundField> <asp:BoundField DataField="city" HeaderText="Town\City"> <ItemStyle BorderColor="#DDDDDD" BorderWidth="1px" CssClass="grditemstyle" Font-Bold="False" HorizontalAlign="Left" VerticalAlign="Top" /> <HeaderStyle BorderColor="#DDDDDD" BorderWidth="1px" Font-Bold="False" HorizontalAlign="Left" Width="10%" /> </asp:BoundField> <asp:BoundField DataField="postcode" HeaderText="Post Code"> <ItemStyle BorderColor="#DDDDDD" BorderWidth="1px" CssClass="grditemstyle" Font-Bold="False" HorizontalAlign="Left" VerticalAlign="Top" /> <HeaderStyle BorderColor="#DDDDDD" BorderWidth="1px" Font-Bold="False" HorizontalAlign="Left" Width="10%" /> </asp:BoundField> <asp:BoundField DataField="phone" HeaderText="Phone"> <ItemStyle BorderColor="#DDDDDD" BorderWidth="1px" CssClass="grditemstyle" Font-Bold="False" HorizontalAlign="Left" VerticalAlign="Top" /> <HeaderStyle BorderColor="#DDDDDD" BorderWidth="1px" Font-Bold="False" HorizontalAlign="Left" Width="20%" /> </asp:BoundField> <asp:TemplateField> <HeaderTemplate> Select </HeaderTemplate> <ItemTemplate> <input name="MyRadioButton" type="radio" value='<%# Eval("crm_suspects_detail_id") %>' /> </ItemTemplate> <HeaderStyle BorderColor="#DDDDDD" BorderWidth="1px" Font-Bold="False" HorizontalAlign="Center" /> <ItemStyle BorderColor="#DDDDDD" BorderWidth="1px" CssClass="grditemstyle" HorizontalAlign="Center" /> </asp:TemplateField> </Columns> <RowStyle BackColor="Transparent" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" /> <PagerStyle BorderColor="#DDDDDD" BorderStyle="Solid" BorderWidth="0px" CssClass="grditemstyle" HorizontalAlign="Right" /> <HeaderStyle BackColor="White" CssClass="grdhdrstyle DataGridFixedHeader" Font-Bold="False" HorizontalAlign="Left" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> </asp:Panel> Code (markup): ------------- Try Dim cmdsqlcmd As New SqlCommand("[ts_crm_suspects_details_LoadAll_by_user_id]", MyConn) cmdsqlcmd.CommandType = CommandType.StoredProcedure cmdsqlcmd.Parameters.Add(New SqlParameter("@company_name", Data.SqlDbType.NVarChar, 250)).Value = "" cmdsqlcmd.Parameters.Add(New SqlParameter("@crm_company_country_id", Data.SqlDbType.Int)).Value = "5" cmdsqlcmd.Parameters.Add(New SqlParameter("@crm_company_group_id", Data.SqlDbType.Int)).Value = Convert.ToInt32(Session("group_id")) cmdsqlcmd.Parameters.Add(New SqlParameter("@is_deleted", Data.SqlDbType.Bit)).Value = False cmdsqlcmd.Parameters.Add(New SqlParameter("@flag", Data.SqlDbType.Int)).Value = 2 cmdsqlcmd.Parameters.Add(New SqlParameter("@user_id", Data.SqlDbType.Int)).Value = 3 Dim da = New SqlDataAdapter(cmdsqlcmd) Dim dt As New DataTable() da.Fill(dt) grdsuspect.DataSource = dt grdsuspect.DataBind() Session("searchtext") = "" Catch ex As Exception ''lblError.Text = ex.Message End Try Code (markup):
The are some free JQeury grids that can replace DataGrid. You can try one of these jqGrid - http://www.trirand.com/blog/?page_id=5 flexigrid - http://www.flexigrid.info