如何制作命令按钮组 [英] How make command button group

查看:64
本文介绍了如何制作命令按钮组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个像列表一样的命令按钮组我的意思是我想添加按钮列表

它基本上等于列表框它应该包含按钮

如何要做到这一点

解决方案

 <%@     Page    语言  =  C#    AutoEventWireup   =  True   %>  

< !DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // EN

http://www.w3。 org / TR / xhtml1 / DTD / xhtml1-transitional.dtd >
< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = 服务器 >
< title > 按钮CommandName示例< / title >
< script runat = server >

void CommandBtn_Click(对象发​​件人,CommandEventArgs e)
{

switch (e.CommandName)
{

case 排序

// 调用方法对列表进行排序。
Sort_List(( String )e.CommandArgument);
break ;

case 提交

// 显示单击提交按钮的消息。
Message.Text = 您点击了提交按钮;

// 测试命令参数是否为空字符串()。
if (( String )e.CommandArgument ==
{
// 结束消息。
Message.Text + = ;
}
其他
{
// < span class =code-comment>显示命令参数的错误消息。

Message.Text + = ,但命令参数未被识别。;
}
break ;

默认

// 无法识别命令名称。显示错误消息。
Message.Text = 命令名未被识别。;
break ;

}

}

void Sort_List( string commandArgument)
{

switch (commandArgument)
{

case 升序

// 插入代码以此处按升序对列表进行排序。
Message.Text = 您点击了按升序排序按钮。;
break ;

case Descending

// 插入代码以此处按降序对列表进行排序。
Message.Text = 您点击了降序排序按钮。;
break ;

默认

// 无法识别命令参数。显示错误消息。
Message.Text = 命令参数未被识别。;
break ;

}

}

< / script >

< / head >

< 正文 >

< 表单 id = form1 < span class =code-attribute> runat
= server >

< h3 > 按钮CommandName示例< / h3 >

单击其中一个命令按钮。

< br / > < br / >

< asp:Button id = Button1

< span class =code-attribute>
文字 = 按升序排序

CommandName = 排序

CommandArgument = 升序

OnCommand = CommandBtn_Click

runat = server / >

& nbsp;

< asp:按钮 id = Button2

Text = Sort Descending

CommandName = 排序

CommandArgument = 降序

OnCommand = CommandBtn_Click

runat = server / >

< br / > < br / >

< asp:按钮 id = Button3

文字 = 提交

CommandName = 提交

OnCommand = CommandBtn_Click

runat = 服务器 / >

& nbsp;

< asp:按钮 id = Button4

文本 = 未知命令名称

CommandName = UnknownName

< span class =code-attribute> CommandArgument = UnknownArgument

< span class =code-attribute> OnCommand = CommandBtn_Click

runat = server / >

& nbsp;

< asp:按钮 id = Button5

文本 = 提交未知命令参数

CommandName = 提交

CommandArgument = UnknownArgument

OnCommand = CommandBtn_Click < span class =code-attribute>

< span class =code-attribute> runat = 服务器 / >

< br / > < br / >

< asp:Label id = 消息 runat = 服务器 / >

< / form >

< / body >
< / html >


i want to make a command button group like list i mean i want to add button to list
it is basically equal as list box it should contain buttons
how to do this

解决方案

<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<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>


这篇关于如何制作命令按钮组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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