Single quoation mark in C# means, that this is char[1] type and not a string. All strings should be in double quotation marks. Only when you need to declare a single char you use single quote.
>Sorry, I was probably a bit confusing in my message. I tried this first:
>
>
if (this.cboStatus.SelectedValue == 11 || this.cboStatus.SelectedValue == 7)
>
>which didn't work because SelectedValue is apparently a string. I thought it would have been an int as it was bound to an int value.
>
>So I then tried this:
>
>
if (this.cboStatus.SelectedValue == '11' || this.cboStatus.SelectedValue == '7')
>
>Which didn't work either.
>
>I eventually got it right with this:
>
>
if (this.cboStatus.SelectedValue == "11" || this.cboStatus.SelectedValue == "7")
>
>So, it seems that single and double quotation marks are not interchangeable in C# as they are in VFP. Is that correct?
>
>
>
>>Looks like you need to cast the two strings as ints : (int)"11", no?
>>
>>
>>>Hi,
>>>
>>>I want to compare the SelectedValue of a Drop Down List with a status value, but I'm getting this error:
>>>
>>>Operator '==' cannot be applied to operands of type 'string' and 'int
>>>
>>>My code is:
>>>
>>>
UPDATE: changed the next line to include "" marks and got it fixed, I had been using single quotations and that wasn't working>>>
if (this.cboStatus.SelectedValue == "11" || this.cboStatus.SelectedValue == "7")
>>> {
>>> this.lblDeathDate.Visible = true;
>>> this.txtDeathDate.Visible = true;
>>> this.btnDisplayDeathDateCalendar.Visible = true;
>>> }
>>>
>>>My DropDownList definition is:
>>>
>>>
<mm:mmDropDownList ID="cboStatus" runat="server" BindingSource="Status" BindingSourceDisplayMember="Status"
>>> BindingSourceValueMember="StatusPK" BindingValueSource="Policy" BindingValueSourceMember="StatusFK"
>>> Enabled="False" AutoPostBack="true" OnTextChanged="cboStatus_TextChanged">
>>> </mm:mmDropDownList>
>>>
>>>
>>>What do I need to do to compare this?
If it's not broken, fix it until it is.
My Blog