动态生成table加CSS+js
2012-11-21 22:05
399 查看
string connStr = ConfigurationManager.ConnectionStrings["sqlservercon"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from T_BoWen";
SqlDataReader reader = cmd.ExecuteReader();
TableRow Row1 = new TableRow();
TableCell cell1 = new TableCell();
cell1.Attributes.Add("style", "width:20px;font-weight:bolder;");
cell1.Text ="标题";
//此位置用来写博客名的超链接
TableCell cell2 = new TableCell();
cell2.Attributes.Add("style", "width:655px;font-weight:bolder;");
cell2.Text ="" ;
TableCell cell3 = new TableCell();
cell3.Attributes.Add("style", "width:50px;font-weight:bolder;");
cell3.Text ="阅读";
TableCell cell4 = new TableCell();
cell4.Attributes.Add("style", "width:80px;font-weight:bolder;");
cell4.Text = "评论";
TableCell cell5 = new TableCell();
cell5.Attributes.Add("style", "width:130px;font-weight:bolder;");
cell5.Text = "评论权限";
TableCell cell6 = new TableCell();
cell6.Attributes.Add("style", "width:120px;font-weight:bolder;");
cell6.Text = "操作";
Row1.Cells.Add(cell1);
Row1.Cells.Add(cell2);
Row1.Cells.Add(cell3);
Row1.Cells.Add(cell4);
Row1.Cells.Add(cell5);
Row1.Cells.Add(cell6);
Table1.Rows.Add(Row1);
for (int i = 0; reader.Read(); i++)
{
TableRow Row = new TableRow();
//新建列
if (i <15)
{
TableCell td1 = new TableCell();
td1.Attributes.Add("style", "width:20px;border-top:solid 1px #dddddd;text-decoration:none;");
//td1.Attributes.Add("onmousemove", "this.style.backgroundColor='#fbf8d5';");
td1.Text ="<a href='#'>"+reader.GetString(reader.GetOrdinal("FName"))+"</a>";
//此位置用来写博客名的超链接
TableCell td2 = new TableCell();
td2.Attributes.Add("style", "width:655px;border-top:solid 1px #dddddd;");
td2.Text = reader.GetDateTime(reader.GetOrdinal("FTime")).ToString();
TableCell td3 = new TableCell();
td3.Attributes.Add("style", "width:50px;border-top:solid 1px #dddddd;");
td3.Text = reader.GetInt32(reader.GetOrdinal("FNumber")).ToString();
TableCell td4 = new TableCell();
td4.Attributes.Add("style", "width:80px;border-top:solid 1px #dddddd;");
td4.Text = reader.GetInt32(reader.GetOrdinal("FPinLun")).ToString();
TableCell td5 = new TableCell();
td5.Attributes.Add("style", "width:100px;font-size:13px;border-top:solid 1px #dddddd;");
td5.Text = "<a href='#'>禁止编辑</a>";
TableCell td6 = new TableCell();
td6.Attributes.Add("style", "width:128px;height:34px;font-size:13px;border-top:solid 1px #dddddd;");
td6.Text = "<a href='#'>编辑</a>" + "|"+"<a href='#'>置顶</a>"+"|"+ "<a href='#'>删除</a>";
Row.Cells.Add(td1);
Row.Cells.Add(td2);
Row.Cells.Add(td3);
Row.Cells.Add(td4);
Row.Cells.Add(td5);
Row.Cells.Add(td6);
//动态生成table,当鼠标经过时,给行加上背景颜色,离开时把背景颜色支掉
Row.Attributes.Add("onmousemove", "this.style.backgroundColor='#fbf8d5';");
Table1.Rows.Add(Row);
Row.Attributes.Add("onmouseout", "this.style.backgroundColor='White';");
}
}
}
}
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "select * from T_BoWen";
SqlDataReader reader = cmd.ExecuteReader();
TableRow Row1 = new TableRow();
TableCell cell1 = new TableCell();
cell1.Attributes.Add("style", "width:20px;font-weight:bolder;");
cell1.Text ="标题";
//此位置用来写博客名的超链接
TableCell cell2 = new TableCell();
cell2.Attributes.Add("style", "width:655px;font-weight:bolder;");
cell2.Text ="" ;
TableCell cell3 = new TableCell();
cell3.Attributes.Add("style", "width:50px;font-weight:bolder;");
cell3.Text ="阅读";
TableCell cell4 = new TableCell();
cell4.Attributes.Add("style", "width:80px;font-weight:bolder;");
cell4.Text = "评论";
TableCell cell5 = new TableCell();
cell5.Attributes.Add("style", "width:130px;font-weight:bolder;");
cell5.Text = "评论权限";
TableCell cell6 = new TableCell();
cell6.Attributes.Add("style", "width:120px;font-weight:bolder;");
cell6.Text = "操作";
Row1.Cells.Add(cell1);
Row1.Cells.Add(cell2);
Row1.Cells.Add(cell3);
Row1.Cells.Add(cell4);
Row1.Cells.Add(cell5);
Row1.Cells.Add(cell6);
Table1.Rows.Add(Row1);
for (int i = 0; reader.Read(); i++)
{
TableRow Row = new TableRow();
//新建列
if (i <15)
{
TableCell td1 = new TableCell();
td1.Attributes.Add("style", "width:20px;border-top:solid 1px #dddddd;text-decoration:none;");
//td1.Attributes.Add("onmousemove", "this.style.backgroundColor='#fbf8d5';");
td1.Text ="<a href='#'>"+reader.GetString(reader.GetOrdinal("FName"))+"</a>";
//此位置用来写博客名的超链接
TableCell td2 = new TableCell();
td2.Attributes.Add("style", "width:655px;border-top:solid 1px #dddddd;");
td2.Text = reader.GetDateTime(reader.GetOrdinal("FTime")).ToString();
TableCell td3 = new TableCell();
td3.Attributes.Add("style", "width:50px;border-top:solid 1px #dddddd;");
td3.Text = reader.GetInt32(reader.GetOrdinal("FNumber")).ToString();
TableCell td4 = new TableCell();
td4.Attributes.Add("style", "width:80px;border-top:solid 1px #dddddd;");
td4.Text = reader.GetInt32(reader.GetOrdinal("FPinLun")).ToString();
TableCell td5 = new TableCell();
td5.Attributes.Add("style", "width:100px;font-size:13px;border-top:solid 1px #dddddd;");
td5.Text = "<a href='#'>禁止编辑</a>";
TableCell td6 = new TableCell();
td6.Attributes.Add("style", "width:128px;height:34px;font-size:13px;border-top:solid 1px #dddddd;");
td6.Text = "<a href='#'>编辑</a>" + "|"+"<a href='#'>置顶</a>"+"|"+ "<a href='#'>删除</a>";
Row.Cells.Add(td1);
Row.Cells.Add(td2);
Row.Cells.Add(td3);
Row.Cells.Add(td4);
Row.Cells.Add(td5);
Row.Cells.Add(td6);
//动态生成table,当鼠标经过时,给行加上背景颜色,离开时把背景颜色支掉
Row.Attributes.Add("onmousemove", "this.style.backgroundColor='#fbf8d5';");
Table1.Rows.Add(Row);
Row.Attributes.Add("onmouseout", "this.style.backgroundColor='White';");
}
}
}
}
相关文章推荐
- 动态生成table加CSS+js
- js动态生成table 经典
- js动态生成table的一行 并且是复制的当前行 列都一起生成了
- JS动态生成Table
- JS实现动态生成html table表格的方法分析
- js 根据数组分组动态生成table(相同项合并)
- 用js动态生成css代码
- js动态生成css代码
- JS 排序输出实现table行号自增前端动态生成的tr
- 用js动态生成css代码的两种方法!
- js动态生成table【转】js动态生成table【转】
- JS 排序输出实现table行号自增前端动态生成的tr
- angularjs+bootstrapTable为动态生成的代码添加事件
- 使用PHP来动态生成CSS/JS
- js 根据数组分组动态生成table(相同项合并)
- AngularJs+Bootstrap Table $compile动态生成html
- js通过后台配置动态生成html table表格
- 笔记-js中动态生成、删除table
- CSS生成动态目录结构:COOLjsMenuPRO组件
- dynamic-css 动态 CSS 库,使得你可以借助 MVVM 模式动态生成和更新 css,从 js 事件和 css 选择器的苦海中脱离出来