asp.netext.nettimefield

set mintime and maxtime of timefield dynamically in ext.net


I am working with EXT.NET 1.2 I want to set minTime and maxTime from codebehind(from cs Page).

I ha dwritten following code but not working that code.. is their any mistake or is ther any another method(through Javascript)??

Code

tmFrom.Increment = 30;
string strmin = obj.startTime.ToShortTimeString();
DateTime dtmin = DateTime.ParseExact(strmin, "H:mm tt", CultureInfo.InvariantCulture);
string strmax = obj.endTime.ToShortTimeString();
DateTime dtmax = DateTime.ParseExact(strmax, "H:mm tt", CultureInfo.InvariantCulture);
tmFrom.Format = "H:mm";
tmFrom.MinTime = dtmin.TimeOfDay;
tmFrom.MaxTime = dtmax.TimeOfDay;

I am setting minTime and maxTime from Database value.


Solution

  • Based on your code sample, it appears obj.startTime and obj.endTime are both already DateTime objects. You should not have to convert into Strings, then back into DateTime objects.

    The following sample demonstrates the complete scenario.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var startTime = DateTime.Now.AddMinutes(-215);
            var endTime = DateTime.Now.AddMinutes(215);
            var time = this.TimeField1;
    
            time.Increment = 30;
            time.Format = "H:mm";
            time.MinTime = startTime.TimeOfDay;
            time.MaxTime = endTime.TimeOfDay;
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    
        <ext:TimeField ID="TimeField1" runat="server" FieldLabel="Time" />
    </body>
    </html>
    

    Hope this helps