Create a DataGrid with a fixed table header and table body scrolling
Chapter E of Mencius
When using the DataGrid, sometimes the table header must be fixed and the content of the table body can be rolled. The following code implements this function.
View examples
Showfixedheader. aspx
<Title ID = "lucky_elove" runat = "server"> </title> <meta name = "generator" content = "Microsoft Visual Studio. net 7.0 "> <meta name =" code_language "content =" Visual Basic 7.0 "> <meta name =" vs_defaultclientscript "content =" JavaScript "> <meta name =" vs_targetschema "content = "http://schemas.microsoft.com/intellisense/ie5">
Showfixedheader. aspx. VB
Imports system <br/> imports system. data <br/> imports system. data. oledb <br/> public class showfixedheader <br/> inherits system. web. UI. page <br/> protected withevents Table1 as system. web. UI. htmlcontrols. htmltable <br/> protected withevents datagrid1 as system. web. UI. webcontrols. dataGrid <br/> protected withevents form1 as system. web. UI. htmlcontrols. htmlform <br/> protected withevents lucky_elove Htmlcontrols. htmlgenericcontrol <br/> # region "Web Form Designer generated code" <br/> 'this call is required by the web form designer. <br/> <system. diagnostics. debuggerstepthrough> private sub initializecomponent () <br/> end sub <br/> private sub page_init (byval sender as system. object, byval e as system. eventargs) handles mybase. init <br/> 'codegen: This method call is required by the web M designer <br/> 'do not modify it using the code editor. <br/> initializecomponent () <br/> end sub <br/> # End Region <br/> private sub page_load (byval sender as system. object, byval e as system. eventargs) handles mybase. load <br/> lucky_elove.innertext = "[wonderful world of Meng xianhui]-Implementation of cross-column headers" <br/> table1.rows (0 ). cells (0 ). innertext = "[wonderful world of Meng xianhui ]. net version: The latest article "<br/> table1.rows (0 ). cells (1 ). innertext = "article information" <br/> T Able1.rows (1 ). cells (0 ). innertext = "article title" <br/> table1.rows (1 ). cells (1 ). innertext = "Release Date" <br/> table1.rows (1 ). cells (2 ). innertext = "" <br/> table1.rows (1 ). cells (3 ). innertext = "click rate" <br/> table1.rows (0 ). style. add ("color", "White") <br/> table1.rows (0 ). style. add ("font-weight", "bold") <br/> table1.rows (0 ). cells (0 ). attributes. add ("onclick", _ <br/> "window. open ('HTTP: // lucky_elove.www1.dotnetpl Ayground.com/') ") <br/> table1.rows (0 ). cells (0 ). style. add ("cursor", "hand") <br/> try <br/> dim cnstring as string = "provider = Microsoft. jet. oledb.4.0; Data Source = "_ <br/> + server. mappath ("test. mdb ") <br/> dim cn as new oledbconnection (cnstring) <br/> CN. open () <br/> dim strsql as string = "select top 30 d. title, D. createdate, S. title as PID, D. hitcount "_ <br/> +" from document D inner join subject S on D. PID = S. id order by createdate DESC "<br/> dim cmd as new oledbcommand (strsql, CN) <br/> datagrid1.datasource = cmd. executereader <br/> datagrid1.databind () <br/> CN. close () <br/> Cn = nothing <br/> catch EOLE as oledbexception <br/> response. write ("generate error:" + EOLE. message) <br/> end try <br/> end sub <br/> private sub datagrid1_itemdatabound (byval sender as object, _ <br/> byval e as System. Web. UI. webcontrols. datagriditemeventargs) handles datagrid1.itemdatabound <br/> If e. item. itemtype = listitemtype. item or E. item. itemtype = listitemtype. alternatingitem then <br/> If e. item. cells (0 ). text. length & gt; 26 then <br/> E. item. cells (0 ). attributes. add ("title", E. item. cells (0 ). text) <br/> E. item. cells (0 ). TEXT = E. item. cells (0 ). text. substring (0, 26) + "... "<Br/> end if <br/> E. item. cells (1 ). TEXT = format (system. convert. todatetime (E. item. cells (1 ). text), _ <br/> "YYYY, month, month, day, hour, minute, second ") <br/> end if <br/> end sub <br/> end class <br/> </system. diagnostics. debuggerstepthrough>