一、简介
NumericUpDown也可以称之为微调控件(效果图:<shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 66.75pt; HEIGHT: 27pt" alt="" type="#_x0000_t75"><imagedata o:href="http://www.cnblogs.com/images/cnblogs_com/bluesky521/spinner1.jpg" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image001.jpg"></imagedata></shape>),可以使用它进行一组有关联顺序的值的输入控件。早在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所指定的WebMethod的参数,可用于传递给服务器当前的上下文信息。
Minimum – 最小值.
Maximum - 最大值.
三、 实例
1.在列表中枚举
<asp:TextBox ID="TextBox2" runat="server">星期三</asp:TextBox>
<cc1:NumericUpDownExtender ID="NumericUpDownExtender1" runat="server"Width=100 TargetControlID="TextBox2"
RefValues="星期一;星期二;星期三;星期四;星期五;星期六;星期天" >
<shape id="_x0000_i1026" style="WIDTH: 130.5pt; HEIGHT: 54pt" alt="" type="#_x0000_t75"><imagedata o:href="http://hiphotos.baidu.com/haoyongsheng/pic/item/4a3f5bdf28eac11463279845.jpg" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image002.png"></imagedata></shape>
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代码示例:
<shape id="_x0000_i1027" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>usingSystem;
<shape id="_x0000_i1028" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>usingSystem.Web;
<shape id="_x0000_i1029" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>usingSystem.Collections;
<shape id="_x0000_i1030" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>usingSystem.Web.Services;
<shape id="_x0000_i1031" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>usingSystem.Web.Services.Protocols;
<shape id="_x0000_i1032" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>
<shape id="_x0000_i1033" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>
<shape id="_124_176_Open_Image" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75" o:spid="_x0000_i1034"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image005.gif"></imagedata></shape><shape id="_124_176_Closed_Image" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75" o:spid="_x0000_i1035"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image006.gif"></imagedata></shape>///<summary>
<shape id="_x0000_i1036" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.gif"></imagedata></shape>///NumericUpDown的摘要说明
<shape id="_x0000_i1037" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image008.gif"></imagedata></shape>///</summary>
<shape id="_x0000_i1038" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>[WebService(Namespace="http://tempuri.org/")]
<shape id="_x0000_i1039" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
<shape id="_x0000_i1040" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>[System.Web.Script.Services.ScriptService]
<shape id="_390_700_Open_Image" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75" o:spid="_x0000_i1041"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image005.gif"></imagedata></shape><shape id="_390_700_Closed_Image" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75" o:spid="_x0000_i1042"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image006.gif"></imagedata></shape>publicclassNumericUpDown:System.Web.Services.WebService{
<shape id="_x0000_i1043" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.gif"></imagedata></shape>
<shape id="_x0000_i1044" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.gif"></imagedata></shape>[WebMethod]
<shape id="_459_543_Open_Image" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75" o:spid="_x0000_i1045"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image009.gif"></imagedata></shape><shape id="_459_543_Closed_Image" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75" o:spid="_x0000_i1046"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image010.gif"></imagedata></shape>publicintNextValue(intcurrent,stringtag){
<shape id="_x0000_i1047" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.gif"></imagedata></shape>returnnewRandom().Next(Math.Min(1000,Math.Max(0,current)),1001);
<shape id="_x0000_i1048" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image011.gif"></imagedata></shape>}
<shape id="_x0000_i1049" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.gif"></imagedata></shape>
<shape id="_x0000_i1050" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.gif"></imagedata></shape>[WebMethod]
<shape id="_612_693_Open_Image" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75" o:spid="_x0000_i1051"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image009.gif"></imagedata></shape><shape id="_612_693_Closed_Image" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75" o:spid="_x0000_i1052"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image010.gif"></imagedata></shape>publicintPrevValue(intcurrent,stringtag){
<shape id="_x0000_i1053" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.gif"></imagedata></shape>returnnewRandom().Next(0,Math.Min(1000,Math.Max(0,current)));
<shape id="_x0000_i1054" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image011.gif"></imagedata></shape>}
<shape id="_x0000_i1055" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.gif"></imagedata></shape>
<shape id="_x0000_i1056" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image008.gif"></imagedata></shape>}
<shape id="_x0000_i1057" style="WIDTH: 8.25pt; HEIGHT: 12pt" alt="" type="#_x0000_t75"><imagedata o:href="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image004.gif"></imagedata></shape>
这样就可以控制上下键的执行过程。
http://asp.net/AJAX/Control-Toolkit/Live/NumericUpDown/NumericUpDown.aspx