|
-
February 1st, 2005, 03:15 AM
#1
Converting a String to Integer [C#]
Given a DropDownList box [ddlHour] and a DateTime variable [dtSelected].
I want to update the hour in dtSelected.hour with the ddlHour.SelectedValue however when I try to do the following directly:
dtSelected.Minute = ddlMinute.SelectedValue;
I get the following error:
1) Cannot implicitly convert type 'string' to 'int'
2) Property or indexer 'System.DateTime.Hour' cannot be assigned to -- it is read only
So I guess I have 2 questions; how could I convert the string returned by ddlHour.SelectedValue into an Integer so I can update the dtSelected.hour AND why am I seeing that read-only error? Am I not doing this right at all?
-
February 1st, 2005, 03:30 AM
#2
Re: Converting a String to Integer [C#]
try:
dtSelected.Minute = Convert.ToInt32(ddlMinute.SelectedValue);
-
February 7th, 2005, 03:16 AM
#3
Re: Converting a String to Integer [C#]
When using the following code:
dtSelected.Minute = Convert.ToInt32(ddlMinute.SelectedValue);
I get the following error:
Property or indexer 'System.DateTime.Minute' cannot be assigned to -- it is read only
Can I turn read-only off?
-
February 7th, 2005, 03:32 AM
#4
Re: Converting a String to Integer [C#]
Hmm dtSelected is a DateTime value?.....
Than why U assigned values to read only fields?
Rather Use apropriate constructor.
For example:
dtSelected=new System.DateTime(1979, // Year
07, // Month
28, // Day
22, // Hour
35, // Minute
5, // Second
15, // Millisecond
calendar // Calendar
);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|