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”。
请问,这要怎么解决,以前我这样写,并没有出现类似错误啊。
} 展开
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”。
请问,这要怎么解决,以前我这样写,并没有出现类似错误啊。
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询