Datagrid| News | Generate html| Statistics | It has been a few years since the first contact with pb6.0 to now. NET technology, Computer technology, whether from hardware or software, has made great progress. And the overall level of Chinese programmers in the world is also far behind, which lacks a sound system, The necessary communication and programmer's idea of individual heroism is the main reason. Not long ago in the work encountered a question about using the DataGrid category to display data, the style shown in the following image: I hope to be able to meet similar problems with a friend to provide a solution, and grasp the solution of similar problems.
Problem Analysis:
For example, each course belongs to a different category, and the first category that displays the data needs to be summarized. Using a standard DataGrid is difficult to achieve. It is clear that you need to solve it on your own.
Ideas:
In the final analysis, regardless of the style of the table display, the foreground is a TABLE element of HTML, so if you can read the data dynamically determine the HTML style, and through the div HTML generated to the foreground display, You can control the complex display. This actually contains the process of pushing back from the HTML that is already displayed to the Dynamic HTML generation.
Source Code and comments:
Define class name and number of data bars
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
{
<summary>
Summary description of the classcourse.
</summary>
public class ClassCourse:System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList Specialtyid;
protected System.Web.UI.HtmlControls.HtmlGenericControl Maindiv;
if (! Page.IsPostBack)
{
Appglobal.cboxfillspecialtydata (ref this.) Specialtyid,true);
}
}
#endregion
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Specialtyid.selectedindexchanged + = new System.EventHandler (this. specialtyid_selectedindexchanged);
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
private String createouthtml ()
{
Number of out types and name
DataSet dset=new DataSet ();
dset= add your own function to get data set (Flexible design SQL statement) result is type, number
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.