Click here to Skip to main content
13,505,219 members
Rate this:
Please Sign up or sign in to vote.
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 12-Feb-13 22:42pm
srikanth pachava 13-Feb-13 4:47am
before setting selected item to dropdown that should be bounded

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


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

hope it helps.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.180417.1 | Last Updated 13 Feb 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100