`
justdoithz
  • 浏览: 48666 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论

Button..::.CommandName 属性

阅读更多
获取或设置命令名,该命令名与传递给 Command 事件的 Button 控件相关联。
ASP.NET
<asp:Button CommandName="String" />

属性值

类型:System..::.String

Button 控件的命令名。默认值为 String..::.Empty

实现

IButtonControl..::.CommandName

<!---->

当在网页上具有多个 Button 控件时,可使用 CommandName 属性来指定或确定与每一 Button 控件关联的命令名。可以用标识要执行的命令的任何字符串来设置 CommandName 属性。然后,可以以编程方式确定 Button 控件的命令名并执行相应的操作。

有关命令的附加信息(如 Ascending)可以使用 CommandArgument 属性来指定。

无法通过主题或样式表主题设置此属性。有关更多信息,请参见 ThemeableAttributeASP.NET 主题和外观概述

<!---->

下面的代码示例演示如何使用 CommandName 属性来创建对列表进行排序的 Button 控件。

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<head runat="server">
<title>Button CommandName Example</title>
<script runat="server">

void CommandBtn_Click(Object sender, CommandEventArgs e)
{

switch(e.CommandName)
{

case "Sort":

// Call the method to sort the list.
Sort_List((String)e.CommandArgument);
break;

case "Submit":

// Display a message for the Submit button being clicked.
Message.Text = "You clicked the Submit button";

// Test whether the command argument is an empty string ("").
if((String)e.CommandArgument == "")
{
// End the message.
Message.Text += ".";
}
else
{
// Display an error message for the command argument.
Message.Text += ", however the command argument is not recogized.";
}
break;

default:

// The command name is not recognized. Display an error message.
Message.Text = "Command name not recogized.";
break;

}

}

void Sort_List(string commandArgument)
{

switch(commandArgument)
{

case "Ascending":

// Insert code to sort the list in ascending order here.
Message.Text = "You clicked the Sort Ascending button.";
break;

case "Descending":

// Insert code to sort the list in descending order here.
Message.Text = "You clicked the Sort Descending button.";
break;

default:

// The command argument is not recognized. Display an error message.
Message.Text = "Command argument not recogized.";
break;

}

}

</script>

</head>

<body>

<form id="form1" runat="server">

<h3>Button CommandName Example</h3>

Click on one of the command buttons.

<br /><br />

<asp:Button id="Button1"
Text="Sort Ascending"
CommandName="Sort"
CommandArgument="Ascending"
OnCommand="CommandBtn_Click"
runat="server"/>

&nbsp;

<asp:Button id="Button2"
Text="Sort Descending"
CommandName="Sort"
CommandArgument="Descending"
OnCommand="CommandBtn_Click"
runat="server"/>

<br /><br />

<asp:Button id="Button3"
Text="Submit"
CommandName="Submit"
OnCommand="CommandBtn_Click"
runat="server"/>

&nbsp;

<asp:Button id="Button4"
Text="Unknown Command Name"
CommandName="UnknownName"
CommandArgument="UnknownArgument"
OnCommand="CommandBtn_Click"
runat="server"/>

&nbsp;

<asp:Button id="Button5"
Text="Submit Unknown Command Argument"
CommandName="Submit"
CommandArgument="UnknownArgument"
OnCommand="CommandBtn_Click"
runat="server"/>

<br /><br />

<asp:Label id="Message" runat="server"/>

</form>

</body>
</html>


分享到:
评论

相关推荐

    我的学习心得gridview

    btnPrev.CommandName = (GridView1.PageIndex == 0 ? "1" : GridView1.PageIndex.ToString()); btnNext.CommandName = (GridView1.PageCount == 1 ? GridView1.PageCount.ToString() : (GridView1.PageIndex + 2)....

    gridview的buttonfield获取该行的索引值(实例讲解)

    1.选择gridview控件,创建按纽列buttonfield,将此按纽列的CommandName 设置为Details //本例是为了想要查看改行的详细信息 2.GridView1的属性: OnRowCommand= “btnOpenClick” DataKeyNames=”p_num” //绑定...

    CommandName

    这里写了两种关于CommandName和CommandArgument的使用,一类是在后台写代码实现,一类是直接在控件付给属性值

    npm-skyflow-cli

    Skyflow-开发人员的最好朋友 Skyflow使开发人员的生活更加轻松。 先决条件 Skyflow是在Nodejs中开发的。 您需要或 。 安装 与npm npm install skyflow-cli-g ... commandName : { description : "Description

    CommandLine:使用 jQuery&PHP&Ajax

    commandname --command description. commandname2 --command description. commandname3 --command description. commandname4 --command description.' ); break ; case 'commandname' : $ array [ 'output' ] =...

    discord.js-altyapi:Discord.JS初学者的免费基础结构(v12)

    添加命令时,可以先创建一个名为“ commands ”的文件夹,然后以commandname.js的形式安装一个js文件。 您可以从Events文件夹中的ready.js文件内部更改Bot的状态。 ================= ERN#2088编码 ============...

    neutralinojs-cli:neu cli用于Neutralinojs

    中性 neu cli用于Neutralinojs $ npm i -g @neutralinojs/neu概要neu create &lt;binaryName&gt; neu build [--release] neu run ... exports = { command : 'commandname &lt;action1&gt;' , register : ( command , modules ) =&gt;

    lines-counter

    线计数器 要求: 支持的操作系统:Windows,Linux,MacOS 怎么运行的? 控制台应用程序读取带有数字枚举(由','分隔)的文件行,并找到具有最大总和... "commandName": "Project", "commandLineArgs": "\"argument1\

    Docker-TLDR-时间

    执行并打印tldr commandname 。 然后从您的研究中执行该命令的一些示例。 :open_file_folder: 项目文件 文档名称 描述 .gitignore 一般忽略文件。 针对Python进行了优化。 .dockerignore 生成期间将不会复制的...

    discord-nestjs::alien_monster:Discord.js的NestJS包

    您的不一致机器人令牌commandPrefix *-命令事件的全局前缀allowGuilds允许机器人使用的公会ID列表denyGuilds该机器人使用的公会ID列表allowChannels将命令链接到通道(也可以通过装饰器设置) commandName *-命令...

    ASP.NET Gridview隐藏/显示列源码

    设置CommandName和CommandArgument属性,这样当通过LinkButton引发RowCommand事件时,相关的列都可以隐藏。以前隐藏的列索引存储在一个List中,这些列在建立时,将会被隐藏的。 代码 protected void GridView1_...

    响应 GridView 控件中的按钮事件

    &lt;asp:Button ID="AddButton" runat="server" CommandName="AddToCart" CommandArgument="((GridViewRow) Container).RowIndex %&gt;" Text="Add to Cart" /&gt; &lt;/ItemTemplate&gt; &lt;/asp:TemplateField&gt; 为 ...

    在ASP.NET 2.0中操作数据之四十五:DataList和Repeater里的自定义Button

    为了让DataList有编辑和删除的功能,我们在ItemTemplate里添加了一些button,当点击时,引起postback,并根据button的CommandName属性激发相关的事件。例如,添加一个CommandName为“Edit”的button,在postback时会...

    在RowCommand事件中获取索引值示例代码

    利用e.CommandSource 代码如下: protected void lpg_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == “ItemCollect”) { GridViewRow gvr = (GridViewRow)(((LinkButton)(e.Command...

    C#经典项目经验总结.doc

    4.Button控件的onclick、oncommand、commandname、CommandArgument的区别 . . . Ajax(Asynchronous JavaScript + XML)的定义 使用模型窗口时,重复打开画面的解决方法 解决IIS写Excel的权限问题 脚本发生错误 ...

    gridview 简单代码

    protected void Button1_Click(object sender, EventArgs e) { for (int i = 0; i &lt;= GridView1.Rows.Count - 1; i++) { CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1"); if (cbox....

    CLI-Toolbox:CLI-Toolbox是软件包的集合,这些软件包可通过命令行界面进行智能,快速的操作和问题解决

    要从CMD中自由调用该程序,请创建一个批处理文件(commandname.cmd)并将其放在PATH(PATH环境变量)的文件夹中。 将其放在commandname.cmd文件中: @echo off cd /d \folder\to\the\compiled\sources java ...

    asp.net button 绑定多个参数

    代码如下:CommandName=”id_” CommandArgument='&lt;&#37;#Eval&#40;“id_comments_”&#41;+”,”+Eval&#40;“iscertification_comments_”&#41; %&gt;’ OnCommand=”comment_click” 代码如下:protected void ...

    经典cookie购物车源码[GridView实现]

    &lt;asp:LinkButton ID="LinkButton1" runat="server" CommandName="update"&gt;保存&lt;/asp:LinkButton&gt; &lt;asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel"&gt;取消&lt;/asp:LinkButton&gt; &lt;asp:...

    2.ASP.NET.2.0.高级编程(第4版) [1/7]

    5.5.2 CommandName属性 123 5.5.3 使用客户端JavaScript的按钮 124 5.6 LinkButton服务器控件 126 5.7 ImageButton服务器控件 126 5.8 HyperLink服务器控件 128 5.9 DropDownList服务器控件 128 5.10 从集合中...

Global site tag (gtag.js) - Google Analytics