speedbeeqs
asked on
Convert to C#! Urgent! Help me!
Please help me! Convert this code into C#!!!
Here:
If container.DataItem("IUSER_ LOCKED").G etType.ToS tring = "System.DBNull" Then
oCheckBox.Checked = False
Else
oCheckBox.Checked = CBool(container.DataItem(" IUSER_LOCK ED"))
End If
Here:
If container.DataItem("IUSER_
oCheckBox.Checked = False
Else
oCheckBox.Checked = CBool(container.DataItem("
End If
I think this may be better than that,
if (container.DataItem["IUSER _LOCKED"] == System.DBNull.Value)
{
oCheckBox.Checked = false;
}
else
{
oCheckBox.Checked = Convert.ToBoolean(containe r.DataItem ["IUSER_LO CKED"]);
}
if (container.DataItem["IUSER
{
oCheckBox.Checked = false;
}
else
{
oCheckBox.Checked = Convert.ToBoolean(containe
}
Well, the best and simplest would actually be:
if (container.DataItem["IUSER _LOCKED"] != DBNull.Value)
oCheckBox.Checked = false;
else
oCheckBox.Checked = (bool)container.DataItem[" IUSER_LOCK ED"];
if (container.DataItem["IUSER
oCheckBox.Checked = false;
else
oCheckBox.Checked = (bool)container.DataItem["
If its a data from database, it depends on the database... If you try to cast like that, some time it may throw an exception... Better to go for Convert.ToBoolean.. I think its better to always use Convert.ToXXX than anything else...
this might be better :
oCheckBox.Checked = (container.DataItem["IUSER _LOCKED"] != System.DBNull.Value &&
Convert.ToBoolean(containe r.DataItem ["IUSER_LO CKED"]));
oCheckBox.Checked = (container.DataItem["IUSER
Convert.ToBoolean(containe
ASKER
to Chester_M_Ragel and TheAvenger:
after compile :
Cannot apply indexing with [] to an expression of type 'object'
after compile :
Cannot apply indexing with [] to an expression of type 'object'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok, great!! Thanks Chester_M_Ragel!
thanks all experts for you helps!
thanks all experts for you helps!
oCheckBox.Checked = false;
else
oCheckBox.Checked = (bool)container.DataItem["