js
动态创建div并绑定事件
var div = document.createElement("div");//创建div存放页数
div.className = "tooltip";
div.innerHTML =i;
div.name = "t"+i+"";
div.style.position = "absolute";
div.style.borderstyle = "solid";
div.style.border = "red";
div.style.left = ""+la+"px";
div.style.width = 100;
div.onclick = function xxx() {//将div与事件绑定动态
for (var i = 1; i <= x; i++) {//将table全部隐藏
var q1 = document.getElementById("t" + i + "");
q1.style.display = "none";
}
oooo = this.name//得到具体哪个按钮激发的事件
var q = document.getElementById(oooo);
q.style.display = "block";
};
var son_td = document.createElement("TD");
son_td.appendChild(div);//将div存放至表格TD中
son_tr.appendChild(son_td);
<link type="text/css" rel="Stylesheet" href="css/xwz.css"/>//连接至css
<script type="text/javascript" src="xjs.js"></script>//连接至js
web后台
Table qqq = new Table();//动态创建table
TableRow Row = new TableRow();//新建行
Row.CssClass = "tbiaoge";//为新建行提供classname方便css调整位置
TableRow Row1 = new TableRow();//新建列
Row1.CssClass = "tbiaoge1";
TableCell Cell1 = new TableCell();
string xxxxx = reader.GetString(reader.GetOrdinal("tfl"));//得到数据库中字段为tfl的值
Cell1.Text = xxxxx;
Row1.Cells.Add(Cell1);//没次创建两行,第二行为回复信息只需一列。将每列添加到行中
qqq.Rows.Add(Row);
qqq.Rows.Add(Row1);//将每行添加进table中
xplgl.Controls.Add(qqq);//将动态创建的表格添加到网页指定的空间
Button xb = new Button();
xb.Text = "删除";
xb.CommandName = id.ToString();
xb.BorderStyle = BorderStyle.None;
xb.ForeColor = System.Drawing.Color.Red;//为动态添加的按钮字体颜色赋值
xb.Click += new EventHandler(xsc);//动态为按钮添加事件
public void xsc(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(connStr))
{conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
Button b1 = (Button)sender;//得到具体是哪个按钮触法的时间通过按钮的属性判断连接的时间视哪个
int x = Convert.ToInt32(b1.CommandName);
cmd.CommandText = "delete from xfl where id="+x+"";
cmd.ExecuteNonQuery();
Response.Redirect("xpl.aspx");//跳转页面
}
}
}
网页间的传值
传值
Response.Redirect("gerenxiangxi.aspx?id1="啊啊啊啊啊啊"");
接收
string ooo=Request["id1"];
配置文件中添加数据库连接的方法
添加连接
<connectionStrings>
<add name="sqlcon1" connectionString="data source=XWZ\实例2008;initial catalog=yhgl;user id=sa;password=123" />
</connectionStrings>
调用
string constr =ConfigurationManager.ConnectionStrings["sqlcon1"].ConnectionString;