c# - 制作一个 Buttonfield 执行一个 javascript

标签 c# asp.net c#-4.0

我想在单击 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/

相关文章:

c# - error 26 无法连接到数据库

c# - SignalR:在收到调用结果之前连接已断开

c# - 在 ASP.NET 服务器端验证 Recaptcha 2(无验证码 reCAPTCHA)

c# - 如何提供一个接口(interface)来获取和更新key,value?

c# - 寻找 boolean 语句的解释

c# - ASP.NET MVC 5 中的自定义授权过滤器?

jquery - 无法在页面卸载事件中调用 post 到 asp.net 页面

ASP.Net - 命名容器和 ClientIDMode ="Static"

.Net Regex Lookahead Group with\Z(行尾)异常

c# - 是否有适用于 .Net 3.5 的 C#4.0 更改列表?