asp.net| data
In the development of ASP.net site projects, data is often displayed in tabular format. The most common possibility is the way the DataGrid binds DataSet data. Of the software projects that have been done, there are 3 typical ways of handling tabular data.
1, DataGrid binding data source. This way everyone uses the most, but the DataGrid and ado.net perfect binding way, or unpleasant. Exclusively's DataGrid style is difficult to adapt to the special styles of different projects, and personalization in the DataGrid can be very troublesome.
2, with XML (data) +xsl (style sheet). As you can see, the dataset binding to the DataGrid is a very good mechanism to implement. As shown in the illustration, the implementation of such a table, developers can enjoy the design of the XSL style.
3. Draw the data directly to the HTML. This way some soil, but sometimes very effective, first look at the implementation of the Code. The following code implements the table shown in the previous illustration.
1<table style= "width:100%; Border-collapse:collapse; height:10px ">
2 <tr>
3 <td align= "center" >
4 <table id= "Tblcontainer" class= "msonormaltable" style= "width:380px"; Border-collapse:collapse; height:10px "
5 cellspacing= "0" cellpadding= "6" border= "1" runat= "Server" bordercolor= "#99cccc" >
6 <tr>
7 <TD colspan= "2" align= "Center" >
8 <p><font size= "3" ><strong><font face= "song body" > General Management Department Personnel </font></strong></ Font></p>
9 </td>
Ten </tr>
<tr>
<TD align= "center" bgcolor= "#003399" ><font size= "2" color= "#ffffff" ><STRONG> person name </strong ></FONT></td>
<TD align= "center" bgcolor= "#003399" ><font size= "2" color= "#ffffff" ><STRONG> Department position </strong ></FONT></td>
</tr>
</TABLE>
</td>
</tr>
</table>
Add the label to the cell in the HTML directly using the Add method of ASP.net WebControls.
1public class WebForm2:System.Web.UI.Page
2 {
3
4 struct Personrole
5 {
6 public string name;
7 public string role;
8}
9
Ten protected System.Web.UI.HtmlControls.HtmlTable Tblcontainer;
One public string straudititemid = "A899B637-AC47-42EB-9B61-A61C9C880DDC";
private void Page_Load (object sender, System.EventArgs e)
13 {
14//Place user code here to initialize the page
if (request.querystring["Audititemid"]!= null)
16 {
Straudititemid = request.querystring["Audititemid"]. ToString ();
18}
19
Getteammember (Straudititemid);
21}
22
The Web Forms Designer generated Code #region the Web Forms Designer generated code
Override protected void OnInit (EventArgs e)
25 {
26//
//CodeGen: This call is required for the ASP.net Web forms Designer.
28//
InitializeComponent ();
Base. OnInit (e);
31}
32
/**////<summary>
34///Designer supports the desired method-do not use the Code editor to modify
35///The content of this method.
///</summary>
Notoginseng private void InitializeComponent ()
38 {
this. Load + = new System.EventHandler (this. Page_Load);
40
41}
#endregion
43
The private void Getteammember (string audititemid)
45 {
Strmaster string, Strteamleader, strpm;
ArrayList al = Getteammembername (Audititemid, out Strmaster, out Strteamleader, out strpm);
48
Personrole (pr in AL)
50 {
Wuyi HtmlTableCell cell=new HtmlTableCell ();
The cell. Align = "Center";
The label LBL = new label ();
LbL. Text = Pr.name;
LbL. Font.Size = 9;
56
Cell. Controls.Add (LBL);
HtmlTableRow row=new HtmlTableRow ();
The row. Cells.add (cell);
60
HtmlTableCell cellrole = new HtmlTableCell ();
Cellrole.align = "Center";
The label lblrole = new label ();
Lblrole.text = Pr.role;
LblRole.Font.Size = 9;
66
CELLROLE.CONTROLS.ADD (Lblrole);
The row. Cells.add (Cellrole);
69
TBLCONTAINER.ROWS.ADD (row);
71}
72}
73
Getteammembername private ArrayList (String audititemid, out string strmastername, out string Strteamleader,out string s TRPM)
75 {
ArrayList al = new ArrayList ();
Strmastername = "None";
Strteamleader = "None";
strpm = "None";
80
Bayi Personrole PR;
Pr.name = "John";
Pr.role = "General manager";
Al. ADD (PR);
85
Pr.name = "Dick";
Pr.role = "Deputy General manager";
Al. ADD (PR);
89
Pr.name = "Harry";
Pr.role = "Clerk";
Al. ADD (PR);
93
Pr.name = "Zhao Liu";
Pr.role = "Clerk";
Al. ADD (PR);
97
The return of Al;
99}
100}
In the drawing of the page, in which way should be different from the beholder. In the site development, these 3 ways have a typical application, especially the third one, I found in the solution of some of the page processing performance problems in the application is very effective. In addition to automating layout page controls, personalization is much easier than rewriting render in a DataGrid.