 |
|
 |
Code not working in Firefox........... any fix for this
|
|
|
|
 |
|
 |
i tried all but no success
my code as follows..
on code behind page code
if (!IsPostBack)
{
GridView1.Attributes.Add("style", "table-layout:fixed");
}
---------------------------------------javascript ------------
function start()
{
var a = document.getElementById("a"); //id of div
var t = document.getElementById("GridView1");
var t2 = t.cloneNode(true)
for(i = t2.rows.length -1;i > 0;i--)
t2.deleteRow(i) ;
t.deleteRow(0);
a.appendChild(t2);
}
window.onload = start
------------------------------------html tag
<div id="a" style ="height:200px; width:617px; top: 259px; left: 264px; position: absolute;">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="COMP_COMPANY_ID" DataSourceID="SqlDataSource1"
style="top: 55px; left: -3px; position: absolute; height: 133px; width: 187px" >
<Columns>
<asp:BoundField DataField="COMP_COMPANY_ID" HeaderText="COMP_COMPANY_ID"
InsertVisible="False" ReadOnly="True" SortExpression="COMP_COMPANY_ID" />
<asp:BoundField DataField="COMP_COMPANY_NAME" HeaderText="COMP_COMPANY_NAME"
SortExpression="COMP_COMPANY_NAME" />
<asp:BoundField DataField="COMP_PRODUCT" HeaderText="COMP_PRODUCT"
SortExpression="COMP_PRODUCT" />
<asp:BoundField DataField="COMP_ADD1" HeaderText="COMP_ADD1"
SortExpression="COMP_ADD1" />
<asp:BoundField DataField="COMP_ADD2" HeaderText="COMP_ADD2"
SortExpression="COMP_ADD2" />
<asp:BoundField DataField="COMP_ADD3" HeaderText="COMP_ADD3"
SortExpression="COMP_ADD3" />
</Columns>
</asp:GridView>
</div>
i dnt know where is mistake i am not anle to sort out please help
|
|
|
|
 |
|
 |
Still not properly working on Firefox
|
|
|
|
 |
|
 |
The window.onload in the javascript will work for the last grid added to a page if there are multiple. Nice solution anyhow ... if I get this to work with multiple grids per page I'll post the code.
FYI I am baking all of this logic into a custom GridView which is why I have this problem (Registering the javascript in the Prerender event). If you are manually writing out the javascript on the page then you are good to go.
|
|
|
|
 |
|
 |
Public Class FrozenDataGrid Inherits GridView
Protected Overrides Sub OnInit(ByVal e As EventArgs) MyBase.OnInit(e) Attributes.Add("style", "table-layout:fixed") End Sub
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs) Dim csMan As ClientScriptManager = Page.ClientScript If Not csMan.IsClientScriptBlockRegistered(ClientID & "_ScollableScriptBlock") Then Dim sb As New System.Text.StringBuilder sb.Append("" & Environment.NewLine) sb.Append("function " & ClientID & "_OnStart()" & Environment.NewLine) sb.Append("{" & Environment.NewLine) sb.Append(vbTab & "var t = document.getElementById(""" & ClientID & """);" & Environment.NewLine) sb.Append(vbTab & "var a = document.getElementById(""" & ClientID & "_HeaderDivider"");" & Environment.NewLine) sb.Append(vbTab & "var t2 = t.cloneNode(true);" & Environment.NewLine) sb.Append(vbTab & "for(i = t2.rows.length - 1; i > 0; i--)" & Environment.NewLine) sb.Append(vbTab & vbTab & "t2.deleteRow(i);" & Environment.NewLine) sb.Append(vbTab & "t.deleteRow(0);" & Environment.NewLine) sb.Append(vbTab & "a.appendChild(t2);" & Environment.NewLine) If ShowFooter Then sb.Append(vbTab & "var b = document.getElementById(""" & ClientID & "_FooterDivider"");" & Environment.NewLine) sb.Append(vbTab & "var t3 = t.cloneNode(true);" & Environment.NewLine) sb.Append(vbTab & "while (t3.rows.length > 1)" & Environment.NewLine) sb.Append(vbTab & vbTab & "t3.deleteRow(0);" & Environment.NewLine) sb.Append(vbTab & "t.deleteRow(t.rows.length-1);" & Environment.NewLine) sb.Append(vbTab & "b.appendChild(t3);" & Environment.NewLine) End If sb.Append("}" & Environment.NewLine) sb.Append("if(window.attachEvent){" & Environment.NewLine) sb.Append(vbTab & "window.attachEvent(""onload"", " & ClientID & "_OnStart);" & Environment.NewLine) sb.Append("}else{" & Environment.NewLine) sb.Append(vbTab & "window.addEventListener(""load"", " & ClientID & "_OnStart, false);" & Environment.NewLine) sb.Append("}" & Environment.NewLine) sb.Append("" & Environment.NewLine) csMan.RegisterClientScriptBlock(Page.GetType, ClientID & "_ScollableScriptBlock", sb.ToString) End If MyBase.OnPreRender(e) End Sub
Protected Overrides Sub Render(ByVal writer As HtmlTextWriter) writer.Write("<div id=""" & ClientID & "_HeaderDivider""></div>") If Rows.Count > 10 Then writer.Write("<div style=""overflow-y: scroll; height: 152px"">") End If MyBase.Render(writer) If Rows.Count > 10 Then writer.Write("</div>") End If If ShowFooter Then writer.Write("<div id=""" & ClientID & "_FooterDivider""></div>") End If End Sub End Class <div class="ForumMod">modified on Friday, March 20, 2009 10:41 AM</div>
|
|
|
|
 |
|
 |
I use your control and works excellent... but when the page uses Themes, an error is generated
"La colección de controles no puede modificarse porque el control contiene bloques de código (por ej. <% ... %>)."
|
|
|
|
 |
|
 |
It seems cloning does not seem to save control values, or at least not for selects. I had a select in my footer for use with paging, and on any paging event the value would be reset. I ended up having to store the selectedIndex, then clone, then process the header/footer, and finally restore the selectedIndex so that it would retain the proper value. Just thought I'd throw that out there in case anyone has run into a similar situation.
|
|
|
|
 |
|
 |
Sometimes I get in such a ".Net" mind set I forget about the many cool things you can do with java script. Excellent example and I will use this in many projects.
Thanks much!
|
|
|
|
 |
|
 |
As I change the
<div style="overflow-y: scroll; height: 200px">
to
<div style="overflow: scroll; height: 200px;width:300px;">
then fixed header can not use already. How can fixed this? Thanks!
|
|
|
|
 |
|
 |
Also could you go into more detail about how this works.
|
|
|
|
 |
|
 |
what is a in this code coz it is giving me error on that ( a.appendChild(t2)
)
though i used this code grid view's header is not geeting fixed.
PLease Reply
|
|
|
|
 |
|
 |
This is great, but most of the gridviews have styles, at least for defining the width of the columns, how can I modify the current code to make header and item columns have the same width?
AV
|
|
|
|
 |
|
 |
Xianhui--
It works--you are great! I was looking at the Javascript. I am trying to figure out how to do a fixed footer. For example, my footer displays column totals.
Have you done this before? If you don't have time, it's okay.
Thanks for any help.
Graeme Martin
|
|
|
|
 |
|
 |
OK, this script works when you add a "b" <div> element below the GridView, but I tried to clone just the footer. Is there an efficient way to do this (instead of cloning t again)? function start() { var a = document.getElementById("a"); var b = document.getElementById("b"); var t = document.getElementById("<%=AssignmentGridView.ClientID%>"); var t2 = t.cloneNode(true); var t3 = t.cloneNode(true); if (t2 && t2.rows.length > 0) { //t3 = t2.rows(t2.rows.length-1).cloneNode(true); for(i = t2.rows.length -1;i > 0;i--) { t2.deleteRow(i); } t.deleteRow(0); a.appendChild(t2); if (t3 && t3.rows.length > 0) { while (t3.rows.length > 1) { t3.deleteRow(0); } t.deleteRow(t.rows.length-1); b.appendChild(t3); } } } window.onload = start;
|
|
|
|
 |
|
 |
When you do bi directional column sorting on grid view it dosn't work and shows two headers. I set gridview property as EnableSortingAndPagingCallbacks="true"
|
|
|
|
 |
|
 |
the callback causes the gridview to be rendered again including the header that was deleted by the javascript function. The following code in the databound event of the gridview will fix the problem (i'm using VB code)
If Page.IsCallback Then
Me.GridView1.HeaderRow.Visible = False
End If
|
|
|
|
 |
|
 |
i tried in internet explorer it works fine, but it does not work in firefox... what should i do for this problem. because i like it and i want to use it
Gökmen BULUT
SENIOR SOFTWARE DEVELOPER
|
|
|
|
 |
|
 |
Add this line in the javascript and it will work in Firefox: (see bolded line)
var t = document.getElementById("<%=GridView1.ClientID%>");
var a = document.getElementById("a");
var t2 = t.cloneNode(true)
|
|
|
|
 |
|
 |
Great code I have seen similiar attempts that were extremely large
and did not work as well
|
|
|
|
 |
|
 |
tried both of your last suggestions gives
|
|
|
|
 |
|
 |
I tried the exact code in my grid view. the header is deleted and i see my grid view without any headers.
|
|
|
|
 |
|
 |
Which type browser are you using? and did you download this zip code and run it?
|
|
|
|
 |
|
 |
IE 6. I copy pasted your code.
|
|
|
|
 |
|
 |
Your code attached works in IE 6.0, but not in Firefox. Solution is interesting. I also doesn't understand explanation regarding css. Does it means css should not be used or what?
|
|
|
|
 |
|
 |
yeah it doesn't work.
I use firefox.
I got an error "a is not defined" on line 55 in the javascript function s().
|
|
|
|
 |