Click here to Skip to main content
15,915,160 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a Gridview that shows reservations requested. The Edit is then used to enter the time of acceptance. I need to have the time inserted into the gridview field in the following format HH:mm tt when you do an edit. How can I do that? Can a mask be used on a gridview field?
Here is my Insert and Update fields:
ASP.NET
<InsertParameters>
                <asp:Parameter Name="LogDate" Type="String" />
                <asp:Parameter Name="PatientName" Type="String" />
                <asp:Parameter Name="DOB" Type="String" />
                <asp:Parameter Name="ArrivalTime" Type="String" />
                <asp:Parameter Name="FrontDeskClerk" Type="String" />
                <asp:Parameter Name="RegClerk" Type="String" />
                <asp:Parameter Name="AcceptedTime" Type="String" ConvertEmptyStringToNull="true" />
                <asp:Parameter Name="Notified" Type="String" />
                <asp:Parameter Name="Issues" Type="String" />
                <asp:Parameter Name="Service1" Type="String" />
                <asp:Parameter Name="Service2" Type="String" />
                <asp:Parameter Name="Service3" Type="String" />
            </InsertParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="TextBoxDayDate" Name="LogDate" PropertyName="Text" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="LogDate" Type="String" />
                <asp:Parameter Name="PatientName" Type="String" />
                <asp:Parameter Name="DOB" Type="String" />
                <asp:Parameter Name="ArrivalTime" Type="String" />
                <asp:Parameter Name="FrontDeskClerk" Type="String" />
                <asp:Parameter Name="RegClerk" Type="String" />
                <asp:Parameter Name="AcceptedTime" Type="String" />
                <asp:Parameter Name="Notified" Type="String" />
                <asp:Parameter Name="Issues" Type="String" />
                <asp:Parameter Name="Service1" Type="String" />
                <asp:Parameter Name="Service2" Type="String" />
                <asp:Parameter Name="Service3" Type="String" />
                <asp:Parameter Name="Id" Type="Int32" />
            </UpdateParameters>


What I have tried:

Many different things with no luck. Can a mask be used on a gridview field?
Posted
Updated 28-Jul-16 1:56am
Comments
Karthik_Mahalingam 27-Jul-16 13:27pm    
show the code relevant to gridview.

1 solution

You could use the asp.net ajax MaskEditExtender control to mask a field. Here's a quick example for your reference:

HTML
<asp:TemplateField>
<EditItemTemplate>
   <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("AcceptedTime", "{0:HH:mm} ") %>'></asp:TextBox>
      <cc1:MaskedEditExtender ID="MaskedEditExtender1"  runat="server" 
         Mask="99:99"
         MaskType="Time" 
         TargetControlID="TextBox1" 
         MessageValidatorTooltip="true">
      </cc1:MaskedEditExtender>
      <cc1:MaskedEditValidator 
            ID="MaskedEditValidator1"
             runat="server"
            ControlToValidate="TextBox1"
            ControlExtender="MaskedEditExtender1"
            IsValidEmpty="false"
            EmptyValueMessage="Input time"
            InvalidValueMessage="Time is not valid">
        </cc1:MaskedEditValidator>
</EditItemTemplate>
<ItemTemplate>
      <asp:Label ID="Label1" runat="server" Text='<%# Bind("AcceptedTime") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
 
Share this answer
 
v2
Comments
Member 11598884 28-Jul-16 9:40am    
I have that already in my input textbox the idea is that when I edit the gridview result of that add and update the record I need the mask applied to the gridview column.
Vincent Maverick Durano 28-Jul-16 9:52am    
You just need to format your GridView column like this:

Text='<%# Bind("AcceptedTime", "{0:HH:mm} ") %>'

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900