网格视图按钮 [英] Gridview Button

查看:86
本文介绍了网格视图按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在gridview(动态按钮)中编写Button事件

How to write the Button event in gridview (dynamic button)

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

                    Width="180px" AutoGenerateEditButton="True"

                    onselectedindexchanged="GridView1_SelectedIndexChanged">
                <Columns>
                <asp:TemplateField>
                <ItemTemplate>
                <asp:Label ID="l1" runat="server" Text='<%#Eval("sno")%>' >                </asp:Label>
                    <br>
                </br>
                <asp:Button ID="b1" runat="server" Text="sms"  CommandName="sms" />//i want to write the event for this button
                <asp:Button ID="B21" runat="server" Text="mail"/>
                </ItemTemplate>
                </asp:TemplateField>
                </Columns>
                </asp:GridView>

推荐答案

您需要为此使用OnRowCommand事件.

you need to use OnRowCommand event for that.

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

                    Width="180px" AutoGenerateEditButton="True"

OnRowCommand=GridView1_RowCommand

onselectedindexchanged="GridView1_SelectedIndexChanged">







protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "sms":
                    {
                        //your code here...
                        break;
                    }
                default:
                   break;

        }
}



如果这对您有帮助,那么请投票并将其标记为答案



If this helped you then please Vote and mark it as answer


<%@ Page Language="C#" AutoEventWireup="true"   EnableEventValidation="false" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Button ID="b1" runat="server" Text="sms"  CommandName="sms" onclick="B1_Click" />





protected void B1_Click(object sender, EventArgs e)
    {
        Button1.Text = "santhu";
    }


这篇关于网格视图按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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