newjeep19
asked on
How to a Bool to a System.GUID in C#
I need to convert a boolean value to a Guid using C#.
I get the below error message:
Cannot implicitly convert type 'bool' to 'System.Guid'
My code that caulse the error:
Please help
I get the below error message:
Cannot implicitly convert type 'bool' to 'System.Guid'
My code that caulse the error:
servicesupportrep.Value = chkShowServiceSupportRep.Checked;
Please help
ASKER
Thank you for your reply. Below is the entire code:
private Lookup servicesupportrep = new Lookup();
////SET CHECKBOXES ON PAGE
protected void Page_Load(object sender, EventArgs e)
{
chkShowServiceSupportRep.Checked = rpt_servicesupportrep.ToLower() == "true" ? true: ( rpt_servicesupportrep == "" ? false : true);
}
// FUNCTION saves the record
protected void saveReportSelections(string QuoteId)
{
servicesupportrep.Value = chkShowServiceSupportRep.Checked; // causing the error
}
So why is servicesupportrep.Value a GUID if you are trying to assign it as true or false? GUID is Globaly Unique Identifier. Are you saving this to a DB? Should maybe change the data type for servicesupportrep or you are trying to set the wrong value.
ASKER
servicesupportrep is a lookup. Basically, when the checkbox is checked. Then the name in the lookup field is inserted into a ssrs report.
Sounds more like you are wanting to do an If chkShowServiceSupportRep.C hecked = 'true' then .....(write servicesupportrep.Value where ever it is you are writing it to.) or something like servicesupportrep.Value = chkShowServiceSupportRep.v alue?
ASKER
I tried somthing like this but still get the same error:
if (chkShowServiceSupportRep.Checked == true) { servicesupportrep.Value = true; } else { servicesupportrep.Value = false; }
Then what ever servicessupportrep needs to be created as a boolean not a GUID. Or you need to be setting a different field associated to the "servicesupportrep" record, which is a guid, like "enabled", which would be boolean. Data would look like this in a table.
servicesupportrep enabled Name
xxxxxxxx-xxxx-xxxx-xxxx-xx xxxxxxxxxx TRUE Someone
yyyyyyyy-xxxx-xxxx-xxxx-xx xxxxxxxxxx FALSE SomeoneElse
servicesupportrep enabled Name
xxxxxxxx-xxxx-xxxx-xxxx-xx
yyyyyyyy-xxxx-xxxx-xxxx-xx
ASKER
OK I gotcha....so, I would need to get the Guid of the person whom is on the lookup field and then if there is a Guid (name) there then true else false....correct?
If checkbox is check then insert name associated with the GUID in the lookup should be inserted into the report?
ASKER
Correct?
if (chkShowServiceSupportRep.Checked == true)
{
LookupName(Guid) = servicesupportrep.Value;
}
else
{
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Not knowing any more about your values here you could try something like:
Open in new window