我想在单击 gridview 的 ButtonField 时执行 JavaScript 函数
因为没有onclick 或onclient click present
<asp:ButtonField HeaderText="Submit" Text="Submit" CommandName="Submit" />
最佳答案
处理 RowDataBound
事件。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Presume that the buttonField is at 1st cell
LinkButton link = e.Row.Cells[0].Controls[0] as LinkButton;
if (link != null)
{
link.Attributes.Add("onclick", "alert('Hello');");
}
}
}
关于c# - 制作一个 Buttonfield 执行一个 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9001882/