altas(ajax)控件(十九):上下箭头按钮控件NumericUpDown

一、      简介

NumericUpDown也可以称之为微调控件(效果图:,可以使用它进行一组有关联顺序的值的输入控件。早在delphi时代,就流行使用该控件。而在web上,到今天才真正出现次控件,可见其web实现之难,感谢ajax

NumericUpDown同样也是扩展控件,它扩展的是TextBox。常规的使用有数字的增/减和时间"日期"星期的的增/减。而且它的上下键的图片还可以更改。

它的增/减方式有三种(我所知道的):

1.在列表中枚举。

2.在属性中设置最大、最小值和步长。

3.WebService中映射/减的方法。

 

二、       属性说明

 

<ajaxToolkit:NumericUpDownExtender ID="NUD1" runat="server"

    TargetControlID="TextBox1"

    Width="100"

    RefValues="January;February;March;April"

    TargetButtonDownID="Button1"

    TargetButtonUpID="Button2"

    ServiceDownPath="WebService1.asmx"

    ServiceDownMethod="PrevValue"

    ServiceUpPath="WebService1.asmx"

    ServiceUpMethod="NextValue"

Tag="1" />

TargetControlID被扩展的TextBox的ID

Width -控件扩展的TextBox加上上下按钮键的Width (最小值是 25).

RefValues如果你希望以枚举的方式来/减。那么在这个值中设置枚举值,用”;”分割。如"星期一;星期二;星期三;星期四;星期五;星期六;星期天"

Step步长,每次的/减的长度.默认值是1.

TargetButtonDownID/TargetButtonUpID上下/减按钮的ID.

ServiceDownPath/ServiceUpPath放置上下/减按钮的方法的WebService的物理路径。

ServiceDownMethod/ServiceUpMethod - 上下/减按钮在WebService的方法:

WebService的方法前需要放置声明

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]

Tag - 传递给ServiceDownMethodServiceUpMethod所指定的Web Method的参数,可用于传递给服务器当前的上下文信息。

Minimum最小值.

Maximum最大值.

 

三、       实例

 

1.在列表中枚举

<asp:TextBox ID="TextBox2" runat="server">星期三</asp:TextBox>
          <cc1:NumericUpDownExtender ID="NumericUpDownExtender1" runat="server"   Width=100 TargetControlID="TextBox2"
          RefValues="
星期一;星期二;星期三;星期四;星期五;星期六;星期天"     >

2. 在属性中设置最大、最小值和步长

<asp:TextBox ID="TextBox2" runat="server">10</asp:TextBox>
     &nbsp;&nbsp;
     <cc1:NumericUpDownExtender ID="NumericUpDownExtender1" runat="server" Maximum="1000"
         Minimum="0" Step="50" TargetControlID="TextBox2" Width="100">
     </cc1:NumericUpDownExtender>

3.WebService中映射/减的方法

我们可以为NumericUpDownExtende控件添加两个方法

NumericUpDown.asmx代码示例:

using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;


/// <summary>
/// NumericUpDown 
的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class NumericUpDown : System.Web.Services.WebService {

    [WebMethod]
    
public int NextValue(int current, string tag{
        
return new Random().Next(Math.Min(1000, Math.Max(0, current)), 1001);
    }

    [WebMethod]
    
public int PrevValue(int current, string tag{
        
return new Random().Next(0, Math.Min(1000, Math.Max(0, current)));
    }
    
}

这样就可以控制上下键的执行过程。

http://asp.net/AJAX/Control-Toolkit/Live/NumericUpDown/NumericUpDown.aspx

 

 

posted on 2007-11-08 20:51  董昊(昊子)  阅读(1122)  评论(0编辑  收藏  举报

导航