开发者

Binding time to a textbox

开发者 https://www.devze.com 2022-12-09 15:01 出处:网络
I am using a Masked Editor which is great and simple to use, but I was wondering. Is there a way to bind the time to a textbox that has a masked editor and cause the AM or PM to show up?

I am using a Masked Editor which is great and simple to use, but I was wondering. Is there a way to bind the time to a textbox that has a masked editor and cause the AM or PM to show up?

I know if you type an A or P AM and PM will show up, but how to you get it to appear to a bound textbox of time?

<asp:TextBox ID="txttime" runat="server" Width="90"></asp:TextBox>
                         <ajaxToolkit:MaskedEditExtender ID = "MaskedEditExtender1" AcceptAMPM="true"  ClearTextOnInvalid="true" ClearMaskOnLostFocus="false" runat="server" TargetControlID="txttime"
                         Mask="99:99" MaskType="Time"></ajaxToolkit:MaskedEditExtender>
                         <ajaxToolkit:MaskedEditValidator ID = "MEV"  ControlToValidate="txttime" runat="server" ControlExtender="MaskedEditExtender1" IsValidEmpty="fa开发者_如何转开发lse"></ajaxToolkit:MaskedEditValidator>

Here is the code that binds to the textbox. All i see is the time without AM or PM

DateTime datetime = Convert.ToDateTime(DataBinder.Eval(FormView1.DataItem, "Date"));   
txttime.Text = String.Format("{0:t}", datetime);


Change

MaskType="Number" 

To

MaskType="DateTime"

And include the following parameter:

AcceptAMPM="true"

So it would now be:

<asp:TextBox ID="txttime" runat="server" Width="90"></asp:TextBox>
                         <ajaxToolkit:MaskedEditExtender ID = "MaskedEditExtender1" AcceptAMPM="true"  ClearTextOnInvalid="true" ClearMaskOnLostFocus="false" runat="server" TargetControlID="txttime"
                         Mask="99:99" MaskType="DateTime" AcceptAMPM="true"></ajaxToolkit:MaskedEditExtender>
                         <ajaxToolkit:MaskedEditValidator ID = "MEV"  ControlToValidate="txttime" runat="server" ControlExtender="MaskedEditExtender1" IsValidEmpty="false"></ajaxToolkit:MaskedEditValidator>


ClearMaskOnLostFocus must be set to true. That was the issue. Thanks for the help.

ClearMaskOnLostFocus="true" 

Here's where i found the answer

Click here

0

精彩评论

暂无评论...
验证码 换一张
取 消