您的位置:首页 > 其它

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

2007-10-24 10:09 281 查看
一、简介
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 - 传递给ServiceDownMethod或ServiceUpMethod所指定的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>
  
<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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: