Reputation: 21
In this code Else Part alone working even if i select dropdownlist2.
string Varddl;
if(DropDownList2.SelectedItem.Text.ToString()== null )
{
Varddl = DropDownList2.SelectedItem.Text;
}
else
{
Varddl = DropDownList3.SelectedItem.Text;
}
string OIMSquery="Insert into tablename values('" + varddl + "')";
Upvotes: 1
Views: 123
Reputation: 148110
You will never get null after calling ToString()
and condition will never come true and always else
part of if will execute, you probably need to compare it with empty string.
if(DropDownList2.SelectedItem.Text == "")
Upvotes: 1
Reputation: 9074
put condition like this>>
if(DropDownList2.SelectedItem== null )
{
.
.
}
else
{
}
It will work.
Upvotes: 1