当前位置:网站首页>asp. Net datatable and some notes of table

asp. Net datatable and some notes of table

2022-06-09 19:57:00 Bailu-

DataTable

DataTable table2 = new DataTable();
// Add a row 
table2.Columns.Add(" full name ", typeof(string));
// Add a new line 
DataRow dr = table2.NewRow();
// Set the contents of the first column of the new row 
dr[0] = " Chinese achievement ";

// Add a new line 
DataRow dr2 = table2.NewRow();
// Set the contents of the first column of the new row 
dr2[0] = " Math scores ";
// I think data inversion is used here , Swap ranks // You can view the previous article :DataTable  Exchange of ranks 
for (int i = 0; i < table.Rows.Count; i++)
 {
    
     // title 
     table2.Columns.Add(table.Rows[i]["name"].ToString(), typeof(string));
		
		// Here you get the string , For other displays 
     /*title += "'"+table.Rows[i]["name"].ToString()+"'"; yw+= table.Rows[i]["yw"].ToString(); sx+= table.Rows[i]["sx"].ToString(); if (i != table.Rows.Count - 1) { title += ","; yw+= ","; sx+= ","; } */
     // Chinese achievement 
     dr[table.Rows[i]["name"].ToString()] = table.Rows[i]["yw"].ToString();
     // Math scores 
     dr2[table.Rows[i]["name"].ToString()] = table.Rows[i]["sx"].ToString();
 }
// Add two rows of data 
table2.Rows.Add(dr);
table2.Rows.Add(dr2);
// Front end control binding data 
dateView.DataSource = table2;
// The binding event 
dateView.DataBind();

Table

// Add a row 
TableRow th = new TableRow();
// Add a blank column , title , That is to say Table Inside  TH
th.Cells.Add(new TableHeaderCell());

// Content , That is to say Table Inside  TD
TableRow tlr = new TableRow();
TableCell cel=new TableCell();
cel.Text = " Chinese achievement ";
tlr.Cells.Add(cel);

// Content , That is to say Table Inside  TD
TableRow tlr2 = new TableRow();
TableCell cel2 = new TableCell();
cel2.Text = " Math scores ";
tlr2.Cells.Add(cel2);
for (int i = 0; i < table.Rows.Count; i++)
{
    
	// title , That is to say Table Inside  TH
	TableHeaderCell cellth = new TableHeaderCell();
	cellth.Text = table.Rows[i]["name"].ToString();
	// Add this column to the row 
	th.Cells.Add(cellth);
	
	//wip
	TableCell cell = new TableCell();
	// You can add hyperlinks 
	cell.Text = "<a href='yw.aspx" + "?name=" + table.Rows[i]["name"].ToString() + "&sort='>" + table.Rows[i]["yw"].ToString() + "</a>";
	// Add this column to the row 
	tlr.Cells.Add(cell);
	
	//out
	TableCell cell2 = new TableCell();
	cell2.Text = "<a href='sx.aspx" + "?name=" + table.Rows[i]["name"].ToString() + "&sort='>" + table.Rows[i]["sx"].ToString() + "</a>";
	// Add this column to the row 
	tlr2.Cells.Add(cell2);
}
// take 3 Line add table
Table1.Rows.Add(th);
Table1.Rows.Add(tlr);
Table1.Rows.Add(tlr2);

Add tools

protected WebControl ToolTabCell(String name,Boolean bln)
{
    
	/* Parameters : Pass in table The content of , Can be hyperlinks   Whether it is a content area , Input false Title (th) */
    if (bln)
    {
    
        TableCell cell = new TableCell();
        cell.Text = name;
        return cell;
    }
    else
    {
    
        TableHeaderCell cell = new TableHeaderCell();
        cell.Text = name;
        return cell;
    }
    
    
}
// Use 
// Create a line 
TableRow tlr3 = new TableRow();
// Set the background color of this row 
tlr3.BackColor = System.Drawing.Color.FromName("#F0FFF0");
// Add a column (td)
tlr3.Cells.Add((TableCell)ToolTabCell(" achievement ", true));
原网站

版权声明
本文为[Bailu-]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/160/202206091935593485.html