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

类型转换错误(求助)

残影留香 发布于 2008-05-21 11:01, 1683 次点击
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#eeeeee'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            ((Button)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除:\"" + e.Row.Cells[0].Text + "\"吗?')");   //就是这句有错误说无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.Button”
     }
    }
请高手帮我解决一下
10 回复
#2
hebingbing2008-05-21 11:04
Cells[4].Controls[0]只中不是Button……
#3
残影留香2008-05-21 11:05
我这个删除按钮是Button类型,我并且把这一列转换成模板列了
#4
hebingbing2008-05-21 12:37
e.Row.Cells[0].Text那这个呢?
不过lz还是应该检查你的Cells[4].Controls[0]……
#5
cyyu_ryh2008-05-21 13:00
用linkButtion撒
#6
残影留香2008-05-21 13:43
[bo]以下是引用 [un]cyyu_ryh[/un] 在 2008-5-21 13:00 的发言:[/bo]

用linkButtion撒

LinkButton我用过,这个是可以实现,但是用Button按钮就不行了哈,郁闷!想找出原因,要不然永远都不会知道答案!
#7
cyyu_ryh2008-05-21 13:46
在grievew里面不能转换为Button的类型
#8
残影留香2008-05-21 14:11
[bo]以下是引用 [un]cyyu_ryh[/un] 在 2008-5-21 13:46 的发言:[/bo]

在grievew里面不能转换为Button的类型

这样啊,那没办法了,谢谢你哈!
#9
snipen2008-05-21 14:30
e.Row.Cells[4].FindControl()呢?
#10
OnlyMiss2008-05-21 16:10
gridview里面可以放Button啊   我都用了的   

直接用(Button)(e.Row.FindControl("Button1")  应该没错的
#11
残影留香2008-05-21 16:25
[bo]以下是引用 [un]OnlyMiss[/un] 在 2008-5-21 16:10 的发言:[/bo]

gridview里面可以放Button啊   我都用了的   

直接用(Button)(e.Row.FindControl("Button1")  应该没错的

那我也试一下,看行不行!
1