TechAnc
TechAnc

Reputation: 111

how to return null using findbyvalue of dropdownlist

this is my code

string result = ddllist.FindByValue(lstvalueA).Text;

if there is no lstvalueA in ddllist,null should be assigned to result

can anyone help on this?

Upvotes: 2

Views: 741

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460168

Check if it's null:

string result = null;
ListItem item = ddllist.Items.FindByValue(lstvalueA);
if(item != null)
    result = item.Text;

Upvotes: 3

Related Questions