How to generate the interface display function for DataGrid classification statistics by dynamically generating HTML

zhaozj2021-02-16  59

It has been a few years after entering the IT industry. From the earliest contact PB6.0 to now .NET technology, computer technology has huge progress from hardware or software. And the overall level of Chinese programmers is also far away. After backward, there is a lack of perfect system, the necessary exchanges and programmers's personal heroism is the main reason. Not long ago encountered a problem with DataGrid category display data, displayed by the display: hope Can provide a solution to friends who meet similar problems and have a solution to similar problems.

Analysis of the problem:

For example, each course is different categories, you need to summarize the first category of display data. It is difficult to achieve the above features with standard DataGrid. Obviously, it is obvious to solve itself.

Idea:

In the final analysis, no matter what style of the form is displayed, it is manifested to the front desk is a Table element of HTML, so if you can dynamically determine the HTML style when reading data, the HTML is generated to the front desk, and can be controlled by the DIV. Display. This is actually included in the process of pushing from the existing HTML to dynamic HTML generation.

Source code and annotation:

Define class saving category names and data

public class KeyVal {private string m_Skey; private string m_SVal; public string strKey {get {return m_Skey;} set {m_Skey = value;}} public string strVal {get {return m_SVal;} set {m_SVal = value;}} public KeyVal ()} Public keyval (string skey, string sval) {strkey = SKEY; STRVAL = sval;}}}

Test page code and related functions

using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.web.ui.htmlcontrols; using system.security.principal; using microsoft.Web.ui.webcontrols; using system.text;

Namespace EisWebsite.Webinternet {///

/// ClassCourse's summary description. /// public class ClassCourse: System.Web.UI.Page {protected System.Web.UI.WebControls.DropDownList SpecialtyID; protected System.Web.UI.HtmlControls.HtmlGenericControl MainDiv; // #region private page initialization Void Page_Load (Object Sender, System.Eventargs E) {AppGlobal.cboxfillspecialtyData (Ref this.specialtyid, true);}}

#ndregion

#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///

/// Designer Supports the required method - Do not use the code editor to modify the // / this method. /// private void InitializeComponent () {this.SpecialtyID.SelectedIndexChanged = new System.EventHandler (this.SpecialtyID_SelectedIndexChanged); this.Load = new System.EventHandler (this.Page_Load);} #endregion

Private string createuntml () {

// Take the number of types and name Dataset dset = new dataset (); DSET = Add your own acquisition data set function (flexible design SQL statement) result is type, number

//Appglobal.appsyswebservice.classcourseteteachermainfilters (ITEM);

ArrayList (); foreach (DATAROW DROW IN DSET.TABLES [0] .ROWS) {keyval mobj = new keyval (); mobj.strkey = drow [0] .tostring (); mobj.strval = drow [ 1] .tostring (); mlist.add (mobj);} StringBuilder outhtml = new stringbuilder (); dset = Add your own data set function. Note that the data is sorted and the same

//AppGlobal.AppSysWebService.ClassCourseTeacherFilters(Item); // add a fixed header OutHtml.Append ( "

"); OUTHTML.APpend ("
"); OUTHTML.APpend (" " "
Category " " Course Number " " Course Name " " Credits " " " " ""
II " " III " " " " " " " " Teacher Name " " "); OUTHTML.APpend (" "); String Srctype ="; String NewType = ""; Foreach (DataRow DROW IN DSET.TABLES [0] .ROWS) {Outhtml.Append ("" seabhobj (DROW ["keyValue"]. toString (), mlist); srctype = newtype; outhtml.append ("
" DROW [" CourseID "]. toString () " "); OUTHTML.APpend (" " DROW [" CourseName "]. TOSTRING () " "; OUTHTML. Append ("" drow ["credit"]. TOSTRING () ""); // outhtml.append (""); // Outhtml. Append (" //" "); Switch ( Convert.TOINT16 (DROW ["CourseTime"]. TOSTRING (), 10)) {Case 1: Outhtml.Append ("
√" ""); Outhtml.Append ("< Td width = 43px> "); Outhtml.Append (" "); Break; case 2: Outhtml.Append (" "); OUTHTML.APpend (" √ " " "); Outhtml.append (" "); Break; Case 3: Outhtml.Append (" "); OUTHTML.APpend (" ");

Outhtml.append ("

√" ""); break; default: Outhtml.Append (" "); OUTHTML.APpend ("< Td width = 43px> "); OUTHTML.APpend (" "); Break;} // Outhtml.Append (" ") // outhtml.append (""); OUTHTML.APpend ("" drow ["tnowtring () ""); OUTHTML.APpend ("");} // Add fixed end Outhtml.Append (""); OUTHTML.APpend ("" ); // // DGRID.DataSource = dset; // DGrid.Database (); return outhtml.tostring ();} prince keyval, arraylist mlist) {for (int i = 0; i <= mlist) .Count-1; i ) {IF ((keyval) mList [i]). Strkey == strkey) Return (keyval) mlist [i];} return null;}}

}

转载请注明原文地址:https://www.9cbs.com/read-24634.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.058, SQL: 9