仿博客项目整理笔记

14 篇文章 0 订阅

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;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值