gridview中的一个问题

<asp:GridViewID="GridView1"runat="server"AllowPaging="true"PageSize="5"AutoGenerateCo... <asp:GridView ID="GridView1" runat="server" AllowPaging ="true"
PageSize ="5" AutoGenerateColumns ="false" ShowFooter ="true"
HeaderStyle-BackColor ="brown" FooterStyle-BackColor ="brown"
EditRowStyle-BackColor ="Beige"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnRowEditing="GridView1_RowEditing"
OnRowCancelingEdit="GridView1_RowCancelingEdit"
OnRowDeleting="GridView1_RowDeleting"
OnRowUpdating="GridView1_RowUpdating"
OnRowDataBound="GridView1_RowDataBound" >
<Columns >
<asp:BoundField DataField ="id" HeaderText ="ID" />
<asp:BoundField DataField ="name" HeaderText ="name" ItemStyle-Width ="100px" />
<asp:BoundField DataField ="pwd" HeaderText ="pwd" ItemStyle-Width ="100px"/>
<asp:BoundField DataField ="cb" HeaderText ="cb" ItemStyle-Width ="100px"/>
<asp:CommandField HeaderText ="edit" ShowEditButton="true" ButtonType ="Button" />
<asp:CommandField HeaderText ="delete" ShowDeleteButton ="true" ButtonType ="Button" />

</Columns>

</asp:GridView>

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)

if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)

((LinkButton)e.Row.Cells[5].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('确定要删除:\"" + e.Row.Cells[0].Text + "\"吗?')");
//现在他报错说:
无法将类型为“System.Web.UI.WebControls.DataControlButton”的对象强制转换为类型“System.Web.UI.WebControls.LinkButton”。

请问,这要怎么解决,以前我这样写,并没有出现类似错误啊。

}
展开
 我来答
五千个字节
2010-04-18 · TA获得超过205个赞
知道小有建树答主
回答量:407
采纳率:0%
帮助的人:233万
展开全部
提示说的很清楚了

控件button类型 转化不成linkbutton
<asp:CommandField HeaderText ="delete" ShowDeleteButton ="true" ButtonType ="Button" />

ButtonType ="Button" 不是linkbutton
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式