protected void Page_Load(object sender, EventArgs e)
{
CB_Article.BLL.CB_BigClass bll = new CB_Article.BLL.CB_BigClass(); //创建bll实例
DataSet ds = bll.GetList(""); //调用bll.GetList方法获取数据 Cell_1.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor='#FFFFFF';"); //cell添加onmouseover特性,使单元格背景变色(当鼠标移到单元格上)
Cell_1.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor='#CCCCCC';"); //cell添加onmouserout特性,使单元格背景变色(当鼠标离开时) DataTable dt = ds.Tables[0]; //获取DataSet中的第一个DataTable对象
int Len=0;
if (dt.Rows.Count > 8) //判断dt中数据行数是否大于8
{
Len = 8;
}
else
{
Len = dt.Rows.Count; //不大于8把实际的行数付给Len变量
} for (int i = 0; i < Len; i++)
{
TableCell Cell = new TableCell();
Cell.Attributes.Add("ID", "Cell_" + i); //添加id属性
Cell.Attributes.Add("class", "Daohang"); //添加class=daohang
Cell.Attributes.Add("onmouseover", "javascript:this.style.backgroundColor='#FFFFFF';"); //添加当鼠标移上时变色
Cell.Attributes.Add("onmouseout", "javascript:this.style.backgroundColor='#CCCCCC';"); //添加当鼠标离开时变色
Cell.Text = " <a href='ListArt.aspx?bid=" + dt.Rows[i]["BigclassID"].ToString() + "'> " + dt.Rows[i]["BigClassName"].ToString() + " </a> "; //Cell显示的Text为一个连接
Row_1.Cells.Add(Cell); //把创建的Cells添加到row上
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货