我仿照haoxiao老师的新闻系统怎么总超出所引

来源:百度知道 编辑:UC知道 时间:2024/06/25 07:55:14
我仿照haoxiao老师的新闻系统怎么总超出所引:LinkButton btnDeletd = (LinkButton)e.Row.Cells[0].Controls[0];
所引都为0了,还是超出!!!!!??
就是给GridView的删除LinkButton按钮添加javaScrpt,代码如下:
前台:
<asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True"
>
</asp:GridView>
后台:
public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindToGridView1();
}
}
protected void bindToGridView1()
{
this.GridView1.DataSource = news.getTopNews(10);
this.GridView1.DataKeyNames = new string[] { "newsid" };
this.GridView1.DataBind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//..........................
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.HasC

if (e.Row.HasControls())
{
LinkButton btnDeletd = (LinkButton)e.Row.Cells[0].Controls[0];
;
if (btnDeletd.Text.Equals("删除"))
{
btnDeletd.Attributes.Add("onclick", "javascript:return confirm('" + string.Format("您确认要删除新闻{0}吗?", DataBinder.Eval(e.Row.DataItem, "newstitle")) + "')");
}
}
}
建议改成
LinkButton btnDeletd = e.Rows.FindContorl('删除按钮的名称') as LinkButton;
if(btnDeletd!=null)
{
btnDeletd.Attributes.Add("onclick", "javascript:return confirm('" + string.Format("您确认要删除新闻{0}吗?", DataBinder.Eval(e.Row.DataItem, "newstitle")) + "')");

}

(LinkButton)e.Row.Cells[0].Controls[0]; 应该是这边的问题你对应你的控件看看,逐步调试!