当前位置:编程学习 > C#/ASP.NET >>

高人帮忙看看为什么Attributes.Add没有起作用

 
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        int i;
        //执行循环,保证每条数据都可以更新
        for (i = 0; i < GridView1.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#A5C5DC'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");

                ImageButton imgbtn = (ImageButton)e.Row.FindControl("ImageButton1");
                imgbtn.Attributes.Add("onclick", "return confirm('您确认要删除吗?');");

                ImageButton imgbtn2 = (ImageButton)e.Row.FindControl("ImageButton2");
                imgbtn2.Attributes.Add("onclick=location='userupdate.aspx'", "width=200,height=200");


            }
        }
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
       
       int id = Convert.ToInt32(e.CommandArgument);
       Prodcode pc = new Prodcode();
       string tablename = "TD_CustomProduct";
       int result = pc.Deletprodcode(tablename,id);
       if (result > 0)
       {
         tablename = "TD_CustomProductList";
         result = pc.Deletprodcode(tablename,id);
         if (result > 0)
         {

             Response.Write("<script>alert('删除成功!');</script>");
             int uid = Convert.ToInt32(Session["uid"]);
             InitList(uid);
         }
         else
         {
             Response.Write("<script>alert('删除失败!');</script>");

         }
       }
       else
       {
           Response.Write("<script>alert('删除失败!');</script>");
       }

    }


高人帮忙看一下,我预想的是点击删除图片弹出对话框询问“您确认要删除么?”
点击确定后才进入GridView1_RowCommand这个函数进行删除,但是现在
                ImageButton imgbtn = (ImageButton)e.Row.FindControl("ImageButton1");
                imgbtn.Attributes.Add("onclick", "return confirm('您确认要删除吗?');");
这两句话根本就没起作用,点击删除图片直接就进入GridView1_RowCommand这个函数删除了,没有弹出询问'您确认要删除吗?'的这个对话框。求大侠指点问题出在哪了阿 --------------------编程问答-------------------- 另外
ImageButton imgbtn2 = (ImageButton)e.Row.FindControl("ImageButton2");
                imgbtn2.Attributes.Add("onclick=location='userupdate.aspx'", "width=200,height=200");

这里是想第二图片点击时就自动跳转到userupdate.aspx这个页面去,这样写好像也实现不了,求高人给个写法 --------------------编程问答-------------------- --------------------编程问答--------------------
imgbtn.Attributes.Add("onclick", "return confirm('您确认要删除吗?');");
要改成
imgbtn.Attributes.Add("onclick", "if(!confirm('您确认要删除吗?')){return false;}"); --------------------编程问答-------------------- ImageButton2控件可能在e.Row.Cells[n]里面,用ImageButton imgbtn2 = (ImageButton)e.Row.Cell[n].FindControl("ImageButton2");试试。
具体在哪儿,你单步调试去找吧~
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,