国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

如何通過動態(tài)生成Html靈活實現(xiàn)DataGrid分類統(tǒng)計的界面顯示功能

2024-08-26 00:15:34
字體:
供稿:網(wǎng)友
步入it業(yè)已經(jīng)有幾年的時間了,從最早接觸pb6.0到現(xiàn)在.net技術,計算機技術不論是從硬件還是軟件都有巨大的進步.而中國程序員總體水平在世界上也是遠遠落后,其中缺乏完善的體系、必要的交流和程序員個人英雄主義的思想是主要原因.前不久在工作中遇到一個關于用datagrid分類顯示數(shù)據(jù)的問題,顯示的樣式入下圖所示: 希望能為遇到類似問題的朋友提供一個解決方案,并掌握類似問題的解決方法.

問題剖析:

以上為例,每門課程屬于不同的類別,需要將顯示數(shù)據(jù)的第一項類別進行匯總顯示.用標準的datagrid是難于實現(xiàn)上述功能的.顯然需要依靠自身來解決.

思路:

歸根到底,不論何種樣式的表格顯示,表現(xiàn)到前臺都是html的table元素,因此如果能夠在讀取數(shù)據(jù)時動態(tài)確定html樣式,并通過div將html生成到前臺顯示的話,就可以控制復雜的顯示.這里面其實包含了從已有顯示的html反推到動態(tài)html生成的過程.

源代碼及注釋:

定義類保存類別名字和數(shù)據(jù)條數(shù)

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;
}
}

測試頁代碼和相關函數(shù)

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>
/// classcourse 的摘要說明。
/// </summary>
public class classcourse : system.web.ui.page
{
protected system.web.ui.webcontrols.dropdownlist specialtyid;
protected system.web.ui.htmlcontrols.htmlgenericcontrol maindiv;

//
#region 頁面初始化
private void page_load(object sender, system.eventargs e)
{

if (!page.ispostback)
{
appglobal.cboxfillspecialtydata(ref this.specialtyid,true);
}
}

#endregion

#region web 窗體設計器生成的代碼
override protected void oninit(eventargs e)
{
//
// codegen: 該調(diào)用是 asp.net web 窗體設計器所必需的。
//
initializecomponent();
base.oninit(e);
}

/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </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()
{


//取出類型數(shù)目以及名稱
dataset dset=new dataset();

dset=添加自己的獲取數(shù)據(jù)集的函數(shù)(靈活設計sql語句)結(jié)果為類型、數(shù)目

//appglobal.appsyswebservice.classcourseteachermainfilters(item);


arraylist mlist=new 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=添加自己的數(shù)據(jù)集函數(shù).注意數(shù)據(jù)的排序方式與上同

//appglobal.appsyswebservice.classcourseteacherfilters(item);
//添加固定表頭
outhtml.append("<table cellspacing='0' cellpadding='0' align='center' rules='all' bordercolor='black' border='1'"
+"id='grid'"+
" style='word-break:break-all; border-right:black 1px solid; border-top:black 1px solid; border-left:black 1px solid; width:100%; border-bottom:black 1px solid; border-collapse:collapse'>"
);
outhtml.append("<table cellspacing='0' cellpadding='0' align='center' rules='all' bordercolor='black' border='1'"
+"id='agrid'"+
" style='word-break:break-all;border-right:black 1px solid; border-top:black 1px solid; border-left:black 1px solid; width:100%; border-bottom:black 1px solid; border-collapse:collapse'>");
outhtml.append("<tr align='center'>"+
"<td width='87' style='width: 87px; height: 34px'>類別</td>"+
"<td style='width: 253px; height: 34px'>課程編號</td>"+
"<td style='width: 280px; height: 34px'>課程名稱</td>"+
"<td style='width: 86px; height: 34px'>學分</td>"+
"<td style='width: 140px; height: 34px' >"+
"<table width='100%' height='100%' cellpadding='0' cellspacing='0'>"+
"<tr>"+
"<td align='center'width='33%' ></td>"+
"<td align='center'width='33%'>學期</td>"+

"<td align='center'width='33%' ></td>"+
"</tr>"+
"<tr>"+
"<td align='center' width='33%'>i</td>"+
"<td align='center' width='33%'>ii</td>"+
"<td align='center' width='33%'>iii</td>"+
"</tr>"+
"</table>"+
"</td>"+
"<td style='width: 86px; height: 34px'>教師名稱</td>"+
"</tr>");
outhtml.append("</table><table cellspacing='0' cellpadding='0' align='center' rules='all' bordercolor='black' border='1'"
+"id='bgrid'"+
" style='word-break:break-all;border-right:black 1px solid; border-top:black 1px solid; border-left:black 1px solid; width:775px; border-bottom:black 1px solid; border-collapse:collapse'>");

string srctype="";
string newtype="";
foreach(datarow drow in dset.tables[0].rows)
{
outhtml.append("<tr align='center' height='24px' style='word-break:break-all;'> ");

newtype=drow["keyvalue"].tostring();

if (srctype!=newtype)
outhtml.append("<td width='80' style='width: 80px; height: 34px' rowspan="+seachobj(drow["keyvalue"].tostring(),mlist).strval+">"+seachobj(drow["keyvalue"].tostring(),mlist).strkey+"</td>");
srctype=newtype;

outhtml.append("<td width=231px >"+drow["courseid"].tostring()+"</td>");
outhtml.append("<td width=255px>"+drow["coursename"].tostring()+"</td>");
outhtml.append("<td width=80px>"+drow["credit"].tostring()+"</td>");
// outhtml.append("<td width=100px>");
// outhtml.append("<table width='110' height='100%' cellpadding='0' cellspacing='0' bordercolor='black' border='1'>"+
// "<tr>");
switch (convert.toint16(drow["coursetime"].tostring(),10))
{

case 1:
outhtml.append("<td width=43px>√"+"</td>");
outhtml.append("<td width=43px></td>");
outhtml.append("<td width=43px></td>");
break;
case 2:
outhtml.append("<td width=43px></td>");
outhtml.append("<td width=43px>√"+"</td>");
outhtml.append("<td width=43px></td>");
break;
case 3:
outhtml.append("<td width=43px></td>");
outhtml.append("<td width=43px></td>");
outhtml.append("<td width=3px>√"+"</td>");
break;
default:
outhtml.append("<td width=43px></td>");
outhtml.append("<td width=43px></td>");
outhtml.append("<td width=43px></td>");
break;
}
// outhtml.append("</tr></table>");
// outhtml.append("</td>");
outhtml.append("<td width=79px style='word-break:break-all;'>"+drow["tname"].tostring()+"</td>");
outhtml.append("</tr>");
}
//添加固定表尾部
outhtml.append("</table>");
outhtml.append("</table>");
//
// dgrid.datasource=dset;
// dgrid.databind();
return outhtml.tostring();
}
private keyval seachobj(string strkey, arraylist mlist)
{
for (int i=0;i<=mlist.count-1;i++)
{
if (((keyval)mlist[i]).strkey==strkey)
return (keyval)mlist[i];
}
return null;
}



}

}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 周宁县| 四子王旗| 绥棱县| 元谋县| 合肥市| 彭泽县| 化隆| 博湖县| 安图县| 邻水| 元阳县| 无极县| 弥渡县| 竹山县| 平阴县| 建阳市| 大化| 德江县| 新丰县| 崇明县| 凭祥市| 清徐县| 百色市| 道真| 奉贤区| 鄂托克前旗| 灵寿县| 霍林郭勒市| 新田县| 雅安市| 益阳市| 衢州市| 土默特右旗| 鸡东县| 定结县| 黄龙县| 化德县| 二连浩特市| 安宁市| 西乌| 保德县|