Button 的CommandName 用法

Button 的CommandName 用法<div><asp:ButtonID=”Button1″runat=”server”CommandArgument=”fbi”CommandName=”sort”OnCommand=”Button1_Command”Text=”我是FBI”/>&nbsp;&nbsp;<asp:But…

<div>
        <asp:Button ID=”Button1″ runat=”server” CommandArgument=”fbi” CommandName=”sort”
            OnCommand=”Button1_Command” Text=”我是FBI” />&nbsp; &nbsp;
        <asp:Button ID=”Button2″ runat=”server” CommandArgument=”fu” CommandName=”sort” OnCommand=”Button1_Command”
            Text=”我是福尔摩斯” />
        &nbsp; &nbsp;<asp:Button ID=”Button3″ runat=”server” CommandArgument=”cia” CommandName=”ccia”
            OnCommand=”Button1_Command” Text=”我是CIA” />
        &nbsp; &nbsp;<asp:Button ID=”Button4″ runat=”server” CommandArgument=”cia” CommandName=”bande”
            OnCommand=”Button1_Command” Text=”我是邦德” /><br />
        <asp:Label ID=”Label1″ runat=”server” Text=”Label”></asp:Label><br />
        <br />
        <asp:Label ID=”Label2″ runat=”server” Text=”Label”></asp:Label><br />
        <br />
        <asp:Label ID=”Label3″ runat=”server” Text=”Label”></asp:Label><br />
        <br />
        <br />
        <asp:Label ID=”Label4″ runat=”server” Text=”Label”></asp:Label><br />
        <br />

代码如下:要注意看,关键在这里啊!

 protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Command(object sender, CommandEventArgs e)
    {

        switch (e.CommandName)
        {

            case “sort”:
                Sort_Listt((String)e.CommandArgument);
                break;
            case “ccia”:
                Label3.Text = “我是一个CIA,帅吧!”;
                break;
            case “bande”:
                Label4.Text = “我是邦德啊!假的!!”;
                break;

        }
    }
    void Sort_Listt(string commandArgument)
    {

        switch (commandArgument)
        {

            case “fbi”:
                Label1.Text = “真的!我是一个FBI”;
                break;
            case “fu”:
                Label2.Text = “假的!我不是福尔摩斯,它已经老死了!!”;
                break;

        }
    }

转载于:https://www.cnblogs.com/footleg/archive/2008/03/05/1092648.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/35476.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注