PDA

View Full Version : [CLOSED] Set value to timefield



matrixwebtech
Aug 03, 2014, 7:32 PM
I have a timefield


X.TimeFieldFor(obj => obj.ApplicationStartTime)
.EmptyText("Select")
.MinTime(TimeSpan.FromHours(9))
.MaxTime(TimeSpan.FromHours(18))
.Increment(30)
.Format("hh:mm tt")
.FieldLabel("Start Time")
.AnchorHorizontal("100%")
.AllowBlank(false)
.LabelWidth(125)
.Editable(false)
.SelectOnFocus(true)
.Triggers(
Html.X().FieldTrigger().Icon(TriggerIcon.Clear).Qt ip("Remove selected")
)
.Listeners(l =>
{
l.TriggerClick.Handler = "this.clearValue();";
})

I want to fill this from database value,I fetch 9:00AM from database and try to set with bellow code


X.GetCmp<TimeField>("ApplicationStartTime").SetValue(_tbl_Admin_ApplicationTime_Settings.str _ApplicationStartTime);

but its through an error
Specified cast is not valid.

please let me know correct procedure.

Vladimir
Aug 04, 2014, 10:27 AM
It means that your string is not recognized as time

First, if you use X.GetCmp then you need to pass Format string because GetCmp returns only proxy object which doesn't know about real properties


X.GetCmp<TimeField>("TimeField1", new TimeField.Config() { Format = "hh:mm tt" }).SetValue("9:00AM");


But please ensure that your string is matched to Format, you can check it use the following code


DateTime.ParseExact(value, formatString);


I suggest do not use SetValue but use SelectedTime property which accepts TimeSpan, so just convert your string to TimeSpan and set to SelectedTime property

matrixwebtech
Aug 05, 2014, 4:28 PM
Hi Vladimir
I tried with


X.GetCmp<TimeField>("ApplicationStartTime").SelectedTime = TimeSpan.ParseExact("9:00 AM", "hh:mm tt", null);

but give the same error


Input string was not in a correct format..Please help.

geoffrey.mcgill
Aug 05, 2014, 5:37 PM
but give the same error

In your first example the error was:


Specified cast is not valid.

And now the error is:


Input string was not in a correct format.

It seems like two different errors and two different problems?

Are you 100% sure your input string is the correct format? This doesn't appear to be an issue with Ext.NET code.

matrixwebtech
Aug 05, 2014, 6:19 PM
I post exact what I write in my code.previously vladimir suggest me,and I set SelectedTime property with


TimeSpan.ParseExact("9:00 AM", "hh:mm tt", null)

but still I facing the problem.

Daniil
Aug 06, 2014, 7:11 AM
I don't think that "AM" is a legal thing for a TimeSpan. A TimeSpan is actually a time interval.

Also you probably need to escape the ":" character.

TimeSpan.ParseExact("09:00", "hh\\:mm", null)

See also
http://msdn.microsoft.com/en-US/library/dd992370%28v=vs.110%29.aspx
http://msdn.microsoft.com/en-US/library/ee372287%28v=vs.110%29.aspx

matrixwebtech
Aug 06, 2014, 7:42 AM
Hi Daniil

I simply try this

VIEW


@using Ext.Net
@using Ext.Net.MVC
@{
Layout = null;
var X = Html.X();
}
<script>
var validation = function () {

if (Ext.getCmp("f").isValid() == true) {
return true;
}
else {
return false;
}
}

</script>
<!DOCTYPE html>

<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
@X.ResourceManager()

@(X.FormPanel().Border(false).ButtonAlign(Alignmen t.Left).ID("f")
.Items(

X.TimeField().ID("tf1")
.EmptyText("Select")
.MinTime(TimeSpan.FromHours(9))
.MaxTime(TimeSpan.FromHours(18))
.Increment(30)
.Format("hh:mm tt")
.FieldLabel("Start Time")
.AnchorHorizontal("100%")
.AllowBlank(false)
.LabelWidth(125)
.Editable(false)
.SelectOnFocus(true)
.Triggers(
Html.X().FieldTrigger().Icon(TriggerIcon.Clear).Qt ip("Remove selected")
)
.Listeners(l =>
{
l.TriggerClick.Handler = "this.clearValue();";
})

)

.Buttons
(
X.Button().DirectClickAction("test")
.Listeners(l => { l.Click.Handler = "return validation()"; })


)
)



</div>
</body>
</html>

CONTROLLER


public ActionResult Index()
{
X.GetCmp<TimeField>("tf1").SelectedTime = TimeSpan.ParseExact("9:00", "hh\\:mm", null);

return View();
}

but still now the error is there


Input string was not in a correct format.

Daniil
Aug 06, 2014, 8:10 AM
Your piece of code

TimeSpan.ParseExact("9:00", "hh\\:mm", null)
and mine

TimeSpan.ParseExact("09:00", "hh\\:mm", null)
are different.

matrixwebtech
Aug 06, 2014, 8:19 AM
What difference between 2 codes,but tried with yours and again get the same error.

Daniil
Aug 06, 2014, 8:24 AM
Oh, sorry, I posted the same. Corrected now, please review.

matrixwebtech
Aug 06, 2014, 8:32 AM
Thanks Daniil I tried as per your code,


X.GetCmp<TimeField>("tf1").SelectedTime = TimeSpan.ParseExact("15:00", "hh\\:mm", null);

and its working fine.this can be close.