Create a DataGrid that contains multiple columns and multiple row headers.

Source: Internet
Author: User

Create a DataGrid that contains multiple columns and multiple row headers.

Chapter E of Mencius

When using the DataGrid, sometimes the header needs to span columns and multiple rows. The following code implements this function.

View examples

Showcolspanheader. 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">

Showcolspanheader. aspx. VB

Imports system <br/> imports system. data <br/> imports system. data. oledb <br/> public class showcolspanheader <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 lucky_elove as htmlcontrols. htmlgenericcontrol <br/> # region "Web Form Designer Gene Rated 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) _ <br/> handles mybase. init <br/> 'codegen: This method call is required by the web form 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) _ <br/> 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/> table1.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.dotnetplayground.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 20 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/> d Im 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 d Atagrid1.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), "YYYY, month, day, hour, minute, second ") <br/> end if <br/> end sub <br/> end class <br/> </system. diagnostics. debuggerstepthrough>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.