How to merge complex headers in Asp.net

Source: Internet
Author: User

We need to implement complicated headers and share them with you after more than a day.

Code Implementation

Protected void page_load (Object sender, eventargs e) {datatable tbldatas = new datatable ("datas"); tbldatas. columns. add ("Management Unit", type. getType ("system. string "); tbldatas. columns. add ("region", type. getType ("system. string "); tbldatas. columns. add ("User Name", type. getType ("system. string "); tbldatas. columns. add ("annual contract quantity", type. getType ("system. string "); tbldatas. columns. add ("average outbound pressure", type. getType ("system. string "); tbldatas. columns. add ("actual daily gas supply", type. getType ("system. string "); tbldatas. columns. add ("monthly gas supply", type. getType ("system. string "); tbldatas. columns. add ("accumulated annual gas supply", type. getType ("system. string "); // Add data // tbldatas. rows. add (new object [] {"unit name", "region", "User Name", 10000, 0.14, 222,230,240}); sqlconnection conn = new sqlconnection (); Conn. connectionstring = ""; try {Conn. open (); sqldataadapter SDA = new sqldataadapter ("select G. mssqy as management unit, G. yhdq as region, G. yhm as user name, S. mhtl as annual contract volume, S. myl as average outbound pressure, S. actual daily gas supply of mgql as, S. mygql as monthly gas supply, S. mngql as annual gas supply from DBO. yhgx G Inner join DBO. yhgx_sj s on G. mzcmid = S. mzcmid and G. mxlmid = S. mxlmid and G. yhmid = S. yhmid and G. shyhmid = S. shyhmid; ", Conn); dataset DS = new dataset (); SDA. fill (DS, "data"); // defines the variable used to store the data string gldw; // Management Unit string DQ; // region string yhmc; // user name string ndhtl; // annual contract volume string pjczyl; // average outbound pressure string rsjgql; // daily actual gas supply string ygql; // monthly gas supply string nljql; // cumulative annual gas volume for (INT I = 0; I <Ds. tables ["data"]. rows. count; I ++) {// assign the value to the variable and add it to the target datatable gldw = Ds. tables ["data"]. rows [I] [0]. tostring (). trim (); DQ = Ds. tables ["data"]. rows [I] [1]. tostring (). trim (); yhmc = Ds. tables ["data"]. rows [I] [2]. tostring (). trim (); ndhtl = Ds. tables ["data"]. rows [I] [3]. tostring (). trim (); pjczyl = Ds. tables ["data"]. rows [I] [4]. tostring (). trim (); rsjgql = Ds. tables ["data"]. rows [I] [5]. tostring (). trim (); ygql = Ds. tables ["data"]. rows [I] [6]. tostring (). trim (); nljql = Ds. tables ["data"]. rows [I] [7]. tostring (). trim (); tbldatas. rows. add (new object [] {gldw, DQ, yhmc, ndhtl, pjczyl, rsjgql, ygql, nljql}) ;}} catch (exception ex) {Throw ex ;} finally {Conn. close (); Conn. dispose ();} This. gridview1.datasource = tbldatas; this. gridview1.databind ();} protected void gridview1_rowcreated (Object sender, gridviewroweventargs e) {Switch (E. row. rowtype) {Case datacontrolrowtype. header: String strdate = datetime. now. tostring ("YYYY. mm. dd "); // tablecellcollection tcheader = E. row. cells; tcheader. clear (); // tcheader in the second row. add (New tableheadercell (); tcheader [0]. attributes. add ("colspan", "1"); tcheader [0]. attributes. add ("width", "60"); tcheader [0]. TEXT = "Data Date"; tcheader. add (New tableheadercell (); tcheader [1]. attributes. add ("colspan", "4"); tcheader [1]. attributes. add ("width", "160"); tcheader [1]. TEXT = strdate; tcheader. add (New tableheadercell (); tcheader [2]. attributes. add ("colspan", "1"); tcheader [2]. attributes. add ("width", "165"); tcheader [2]. TEXT = "Statistics Department"; tcheader. add (New tableheadercell (); tcheader [3]. attributes. add ("colspan", "5"); tcheader [3]. attributes. add ("width", "240"); tcheader [3]. TEXT = "hengda R & D </Th> </tr> <tr>"; // tcheader in the third row. add (New tableheadercell (); tcheader [4]. TEXT = "Management Unit"; tcheader [4]. attributes. add ("rowspan", "2"); tcheader. add (New tableheadercell (); tcheader [5]. TEXT = "region"; tcheader [5]. attributes. add ("rowspan", "2"); tcheader. add (New tableheadercell (); tcheader [6]. TEXT = "User Name"; tcheader [6]. attributes. add ("rowspan", "2"); tcheader. add (New tableheadercell (); tcheader [7]. attributes. add ("colspan", "8"); tcheader [7]. TEXT = "unit (Wanfang) </Th> </tr> <tr>"; // Add the fourth row header // tcheader. add (New tableheadercell (); // tcheader [8]. TEXT = "Management Unit"; // tcheader. add (New tableheadercell (); // tcheader [9]. TEXT = "region"; // tcheader. add (New tableheadercell (); // tcheader [10]. TEXT = "User Name"; tcheader. add (New tableheadercell (); tcheader [8]. TEXT = "annual contract volume"; tcheader. add (New tableheadercell (); tcheader [9]. TEXT = "average outbound pressure"; tcheader. add (New tableheadercell (); tcheader [10]. TEXT = "actual daily gas supply"; tcheader. add (New tableheadercell (); tcheader [11]. TEXT = "monthly gas supply"; tcheader. add (New tableheadercell (); tcheader [12]. TEXT = "accumulated annual gas supply </Th> </tr> <tr>"; break ;}}

Related Article

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.