我想在网格视图的ButtonField的单击上执行JavaScript函数
因为没有onclick或onclient click present
<asp:ButtonField HeaderText="Submit" Text="Submit" CommandName="Submit" />发布于 2012-01-31 21:20:17
在grdRewards_RowDataBound中,我们可以编写
If e.Row.RowType = DataControlRowType.DataRow Then
Dim btnbutton As LinkButton = DirectCast(e.Row.Cells(13).Controls(0), LinkButton)
btnbutton.Attributes.Add("onclick", "javascript:return ShowDialog()")发布于 2012-01-25 19:40:06
处理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');");
}
}
}发布于 2012-01-25 19:33:41
你不能在这种情况下使用ButtonField,最好检查一下史蒂夫回答的Javascript before asp:ButtonField click。
编码快乐!!
https://stackoverflow.com/questions/9001882
复制相似问题