Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i gine string value to dropdownlist ,then it gives me error.
error is:Object reference not set to an instance of an object.

my code is:
string name= ViewState["name"].ToString(); 
ddlSearchName.SelectedItem.Text = name;  //here it gives me error.


name is not null ,In name variable value is :abc
Posted
Comments
srikanth pachava 13-Feb-13 4:47am    
before setting selected item to dropdown that should be bounded

1 solution

Hi,

try like below.
C#
string name= ViewState["name"].ToString(); 
object text = ddlSearchName.Items.FindByText(name);
if(text != null)
    ddlSearchName.Items.FindByText(name).Selected = true;


hope it helps.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900