首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >让Buttonfield执行javascript

让Buttonfield执行javascript
EN

Stack Overflow用户
提问于 2012-01-25 19:23:51
回答 4查看 6.9K关注 0票数 3

我想在网格视图的ButtonField的单击上执行JavaScript函数

因为没有onclick或onclient click present

代码语言:javascript
复制
  <asp:ButtonField HeaderText="Submit" Text="Submit" CommandName="Submit"  />
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2012-01-31 21:20:17

在grdRewards_RowDataBound中,我们可以编写

代码语言:javascript
复制
  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()")
票数 0
EN

Stack Overflow用户

发布于 2012-01-25 19:40:06

处理RowDataBound事件。

代码语言:javascript
复制
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');");
            }
        }
    }
票数 5
EN

Stack Overflow用户

发布于 2012-01-25 19:33:41

你不能在这种情况下使用ButtonField,最好检查一下史蒂夫回答的Javascript before asp:ButtonField click

编码快乐!!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9001882

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档