Forum Moderators: open

Message Too Old, No Replies

how can i Fixed header in ASP.NET DataGrid

Fixed header in ASP.NET DataGrid

         

i_am_dhaval

9:31 am on Jul 23, 2009 (gmt 0)

10+ Year Member



here is the code it not working in firefox as we as IE 8

this code only works in ie7

i want to fix the header..i try lot but not working in IE 8

here is the code

---------------

<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>

-------------------

------------------------

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

------------------

Please help

marcel

4:50 pm on Jul 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code looks OK to me, but I haven't tested it though. What exactly is the problem with the header?

i_am_dhaval

5:41 pm on Jul 23, 2009 (gmt 0)

10+ Year Member



when i run this in IE 8 header is not fix

in ie 7 it good

sapose if data come in table but there is heading line like in excel first line is fix (which is heding) rest of the data will be scroll

please help me

Ocean10000

7:34 pm on Jul 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is IE8 running in standard Compliance Mode or Compatibility mode? This will effect how the generated html will be treated.

i_am_dhaval

4:08 am on Jul 24, 2009 (gmt 0)

10+ Year Member



in ie 8 standard Compliance Mode

Ocean10000

4:14 pm on Jul 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



try viewing it in compatibility view. And see if there is any change. I am guessing your page code isn't validating all the way, and ending up in quirks mode for rendering, which is a pain.

If this is the case run a html validator on the page and try to correct the issues it points out.

Ocean10000

7:52 pm on Jul 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I just read in another thread something that might help you get this working in the short term.

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">

i_am_dhaval

6:30 am on Jul 28, 2009 (gmt 0)

10+ Year Member



" <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"> "

thanks, but this is not proper solution

Ocean10000

11:20 pm on Jul 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You are correct it is not a proper solution, but if you were pressed for time it would allow you to solve the problem temporary at least.

Have you tried running the resulting html code though a html validator, and correcting those issues, as much as you can. I have a feeling correcting the html validation errors will correct the IE 8 Rendering issues you are experincing.

i_am_dhaval

12:24 pm on Jul 29, 2009 (gmt 0)

10+ Year Member



the code is not showing error...please help me

hackerjack

1:24 pm on Jul 30, 2009 (gmt 0)

10+ Year Member



I use the real World Grids objects for this, appears to work in IE8 as well

[blogs.msdn.com...]