Hi,
I have problem using C# switch case statement.
C# switch statement pairs with one or more case blocks and a default block.
The case block of code is executed for the matching value of the switch expression value.
The default option code is executed if the switch value doesn't match the case value.
In my case there can be three states: OK, KO or null.
I have error when I try to select in the ddl the value stored in the database table.
c# object reference not set to an instance of an object
in this line
ddl_Status.Items.FindByValue(User_Status).Selected = true;
My complete code below, thanks for any help
string User_Status = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "User_Status"));
switch (User_Status.ToString())
{
case "OK":
ddl_Status.Items.Insert(0, new ListItem("[ === === === ]", ""));
ddl_Status.Items.FindByValue(User_Status).Selected = true;
ddl_Status.Items.Insert(1, new ListItem("KO", "KO"));
break;
case "KO":
ddl_Status.Items.Insert(0, new ListItem("[ === === === ]", ""));
ddl_Status.Items.FindByValue(User_Status).Selected = true;
ddl_Status.Items.Insert(1, new ListItem("OK", "OK"));
break;
case null:
ddl_Status.Items.Insert(0, new ListItem("[ === === === ]", ""));
ddl_Status.Items.Insert(1, new ListItem("OK", "OK"));
ddl_Status.Items.Insert(2, new ListItem("KO", "KO"));
break;
}