从onclick属性调用子过程 [英] calling a sub procedure from onclick attribute

查看:79
本文介绍了从onclick属性调用子过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到数据库中值的gridview控件,在列标记中,我包含一个itemtemplate,并且其中包含一个具有文本属性(Text =''<%#eval("somecolumnname") %>'')的 asp按钮控件.在onclick属性上,我希望它使用某些参数调用另一个子过程(在我的情况下为f).这些参数值应该是所选特定行的ID.
我该怎么办?下面是代码:

I have a gridview control that is bind to a value from database,inside the column tag I included an itemtemplate and within it an asp button control with the text property(Text =''<%#eval("somecolumnname") %>''). on the onclick attribute I want it to call another sub procedure(in my case its f) with some parameter. these parameter values should be the id of that particular row being selected.
How should I do that? below is the code:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="act_id"

            DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="act_id" HeaderText="act_id" ReadOnly="True" SortExpression="act_id" />
                <asp:BoundField DataField="heading" HeaderText="heading" SortExpression="heading" />
                <asp:BoundField DataField="category_id" HeaderText="category_id" SortExpression="category_id" />
                <asp:TemplateField >
                <ItemTemplate >
                <asp:button runat ="server" ID="button" Text ='<%#eval("heading") %>' OnClick ="f" > </asp:button>
                </ItemTemplate>
                </asp:TemplateField>
              </Columns>
        </asp:GridView>


请帮忙!

谢谢


Please help!!

Thank you

推荐答案

您可以像这样使用OnROwCommand事件...

You can use OnROwCommand Event like this...

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="act_id"

            DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand">
            <Columns>
                <asp:BoundField DataField="act_id" HeaderText="act_id" ReadOnly="True" SortExpression="act_id" />
                <asp:BoundField DataField="heading" HeaderText="heading" SortExpression="heading" />
                <asp:BoundField DataField="category_id" HeaderText="category_id" SortExpression="category_id" />
                <asp:TemplateField >
                <ItemTemplate >
                <asp:button CommandName="myButton1" CommandArgument='<%# Eval("act_id") %>' runat ="server" ID="button" Text ='<%#eval("heading") %>' OnClick ="f" > </asp:button>
                </ItemTemplate>
                </asp:TemplateField>
              </Columns>
        </asp:GridView>




在后面的代码中..




In the code behind..

protected void GridView1_RowCommand(object sender,  GridViewCommandEventArgs e)
{
    int act_id = Convert.ToInt32(e.CommandArgument);
    if (e.CommandName == "myButton1")
    {
         string textOnTheButton=Convert.ToString(e.CommandSource);
         //your code here
    }
}



希望对您有帮助



Hope this helps


这篇关于从onclick属性调用子过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆