There is a scroll bar, fixed header ASP.NET DATAGRID implementation

xiaoxiao2021-03-06  42

Source: Unknown Author: Unknown Recommended rating: Visits: 30

Customers have an ASP.NET DATAGRID control with a scroll bar, I have to write: use system; use system.wareb.ui; use system.web.ui.webcontrols; using system.ComponentModel; use system.diagnostics; using system.io Using system.Web.ui.design.WebControls; use system.text; using system.drawing; [assembly: tagprefix ("Microsoft.gtec.dsv", "gtecdsv")] namespace microsoft.gtec.dsv {///

/// Summary description for WebCustomControl1 /// [ToolboxData ( "<{0}: ScrollableFixedHeaderDataGrid runat = server> ")]. public class ScrollableFixedHeaderDataGrid: System.Web .UI.WebControls.DataGrid {protected override void Render (HtmlTextWriter output) {// Use this flag to determine whether the component is in design-time or runtime. // The control will be rendered differently in IDE. // Do not bother to use DataGridDesigner.GetDesignTimeHtml bool designMode = ((Site = null) && (Site.DesignMode)!); // Backing up the properties need to change during the render process string tempLeft = Style [ "LEFT "]; String Temptop = style [" TOP "]; Unit Tempheight = height; string temptablestyle = style [Table-layout"]; // render a "
" Container with scrollbars. Output.writebegintag ("DIV" Output.writeAttribute ("ID", ID "_div"); Output.writeAttribute ("style", "Height:" height ";" // Leave 20px for the vertical scroll bar, // assuming the End-user will not set his scroll bar to more Than 20px. "Width:" (Width.Value 20) "PX;" "TOP:" Style ["TOP"] ";" "

Left: " Style [" l]] ";" "Position:" style ["position"] ";" "overflow-x: auto;" "z-index:" style [" Z-Index "] "; " // Render the scrollbar Differently for design-time and runtime." Overflow-Y: " (DesignMode?" Scroll ":" auto "); Output.write (htmlTextWriter.tagRightchar ); // the datagrid is inside the "

" Element, SO Place It at (0). Style ["left"] = "0px"; style ["TOP"] = "0px"; // RENDER THE DATAGRID. BASE.RENDER (OUTPUT); OUTPUT.WRITEENDTAG ("DIV"); // restore the values ​​style ["left"] = templeft; style ["top"] = temptop; // the folowing rendering is Only necessary under runtime. It has negative impact during design time. if (! designMode) {// Render another copy of the DataGrid with only headers. // Render it after the DataGrid with contents, // so that it is on the top. Z-Index Is More Complex Here. // Set Height To 0, SO That IT Will Adjust On Its Own. Height = New Unit ("0px"); StringWriter SW = New StringWriter (); htmlTextWriter HTW = New HtmlTextWriter (SW) ; // this STY Le Is Important for Matching Column Widths Later. Style [Table-Layout "] =" Fixed "; Base.Render (HTW); StringBuilder SbrenderedTable = SW.GETSTRINGBUILDER (); htw.close (); SW.Close (); Debug.Assert ((sbRenderedTable.Length> 0), "Rendered HTML string is empty Check viewstate usage and databinding.."); string temp = sbRenderedTable.ToString (); if (sbRenderedTable.Length> 0) {// AllowPaging at Top? IF ((allowpaging) && ((PAgerPosition.top ==

Pagerstyle.position || (PagerPosition.topandbottom == Pagerstyle.Position))) {trace.writeLine (TEMP); sbrenderedtable.replace (ID, ID "_pager", 0, (Temp.IndexOf (ID) ID. Length)); Temp = sbrenderedTable.toString (); string Pager = Temp.substring (0, Temp.tolower (). Indexof (@ "<") 5); Trace.Writeline (PAGER); OUTPUT. Write (PAGER); OUTPUT.WRITEENDTAG ("Table"); // Start of Pager's INT Start = Temp.tolower (). Indexof (@ " int End = Temp.tolower (). Indexof (@ "<") 5; // Remove The forpager from the string. preted to render the headers. sbrenderedtable.remove (start, end-start) Trace.writeline (sbrenderedtable.tostring ()); sbrenderedtable.replace (ID "_pager", ID "_headers", 0, (Temp.indexOf (ID "_ Pager") (ID "_ Pager"). Length) ); temp = sbrenderedTable.tostring (); string TableHeaders = Temp.Substring (0, (Temp.tolower ()). Indexof (@ "") 5); Trace.Writeline (TableHeaders); Output. Write (TableHeaders); Output.WriteEndtag ("Table"); string headerid = ID "_Headers"; string pagerID = ID "_Pager"; string divID = ID "_div"; string adjustWidthScript = @ "