注册 登录
编程论坛 ASP.NET技术论坛

确认框问题,,,,,,不明白

lovegosh 发布于 2008-04-16 19:06, 2508 次点击
请问一下,
要在GridView里面  删除一条记录弹出一个确认框.是添加这条语句吗?

 LinkButton1.Attributes.Add("onclick", "return confirm('你是否确定删除?');");

添在哪里啊?    这里?? protected void LinkButton1_Click(object sender, EventArgs e)
                       {  
                          }

可是 GridView 里面  删除按狃里没有内容的啊,  添在里面有用吗?

好象我的不行呢.
那加在哪里?
21 回复
#2
残影留香2008-04-16 19:10
在GridView1_RowDataBound这里加
#3
hebingbing2008-04-16 19:16
新人……
首先欢迎……
在你的deletecommand事件中写上:
(linkbutton)(e.row.cells[列索引]contorls[0]).attribues.add("onclick","return confrim('………………')")
#4
lovegosh2008-04-16 19:17
加那一句就行了吗?
#5
hebingbing2008-04-16 19:19
对了,不是在那个事件里加的,是在2楼说的那个事件里加的……
呵呵……
一句就ok了……
失误……
#6
hebingbing2008-04-16 19:24
一般加上if(e.row.rowtype==datacontrolrowtype.datarow)是绝对有必要的,要不你的页眉页脚也有linkbutton的话那就不好了……
#7
lovegosh2008-04-16 19:25
2楼说的那个事件

在哪里?????
#8
lovegosh2008-04-16 19:31
找到了
呵呵.  

(linkbutton)(e.row.cells[列索引]contorls[0]).attribues.add("onclick","return confrim('………………')")


前面加上if(e.row.rowtype==datacontrolrowtype.datarow)

吗?
#9
hebingbing2008-04-16 19:50
恩,这句来判断是不是数据绑定行……
大概就是这个意思……
datacontrolrowtype枚举有六个元素了……
列举不全了……
#10
lovegosh2008-04-16 19:53
唉呀,我还是不明白啊 .
 protected void GridView1_RowDataBound(objectsender,GridViewRowEventArgs e)
    {
          if(e.Row.RowType==DataControlRowType.DataRow)
        (LinkButton)(e.Row.Cells[3]Contorls[0]).Attributes.Add("onclick", "return confirm('你是否确定删除?');");
    }

这样吗?   有错啊,不明白.那个索引因该是第几列的意思吧?
比如第四列就是3吗?

e.Row.Cells[3]Contorls[0]   到底是什么意思呢?
#11
hebingbing2008-04-16 20:20
e.Row.Cells[3]Contorls[0]
当前行的第四个单元格中的第一个Contorls对象……
#12
lovegosh2008-04-16 20:56
为什么有错呢?
我弄了好久都不出来呢.
晕完了
#13
hebingbing2008-04-16 21:10
protected void GridView1_RowDataBound(objectsender,GridViewRowEventArgs e)
    {
          if(e.Row.RowType==DataControlRowType.DataRow)
{
        ((LinkButton)(e.Row.Cells[3]Contorls[0])).Attributes.Add("onclick", "return confirm('你是否确定删除?')");
}
    }
你复制上试试,要写规范啊……
#14
lovegosh2008-04-16 21:59
那个不是跟我写一样吗?
一模一样的,大哥.呵呵
#15
lovegosh2008-04-16 22:04
还有啊 ,那个Control你写错了哦,后面真的是[]吗?还是()?
呵呵
还是 有3个错
#16
hebingbing2008-04-16 22:20
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
     
     ((LinkButton)(e.Row.Cells[1].Contorls[0])).Attributes.Add("onclick", "return confirm('你确定删除 " + strTitle + " 吗?');");
}
}
我的电脑调试成功……
绝对没有问题……
要是你的还不行那算我没有说……
#17
hebingbing2008-04-16 22:47
奥,我仔细看了看我给你的代码少了一个点(.)仅仅一个点,难道你调试不出来……
呵呵……
对不起啊……
没有开vc手写代码难免有时候就出点毛病……
应该是e.Row.Cells[3].Contorls[0]这样的……
实在对不起……
呵呵……
#18
lovegosh2008-04-16 23:33
呵呵
  if (e.Row.RowType == DataControlRowType.DataRow)
            {
               ((LinkButton)(e.Row.Cells[3].Controls[0])).Attributes.Add("onclick", "return confirm('你确定要删除吗?');");
            }

无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.LinkButton”。

是没有错了,可运行就这样了.
我也头大了,弄了一晚上.
呵呵,谢谢你啊,还给我调试
#19
lovegosh2008-04-16 23:34
再问一下,那个,control对象怎么判断是第几个呢?
#20
lovegosh2008-04-16 23:36
就是那个单元格里有几个control对象就排第几?
#21
lovegosh2008-04-16 23:41

我把那个  "删除 " 放在第一列,又可以哦.((LinkButton)(e.Row.Cells[0].Controls[0]))可以,呵呵.

可是为什么放在第四列就不行呢?
#22
lovegosh2008-04-16 23:45
哎呀,好象又突然行了.
晕.
非常感谢啊!!!
1