This is a migrated thread and some comments may be shown as answers.

RadCombo nullReferenceException

2 Answers 63 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Toni
Top achievements
Rank 1
Toni asked on 29 Jan 2009, 10:48 PM

Hello,

I have a combobox that takes input for the RadUpload. The combo box loads with -- Select Value-- in it but when no selectin is made i get a NullReferenceException occurred.  at this line.

 
string  DBCreativeName = RCBXCreative.SelectedItem.Value;

so I tried to use an if and try catch to fix this
 
 string DBCreativeName = RCBXCreative.SelectedItem.Value;
 
try
 
{
 
if (Convert.ToBoolean(DBCreativeName = ""))
 
 {

    lblstatupload2.Text = "You need to select a creative";
  }

}
catch (NullReferenceException)
  {

lblstatupload2.Text = " you need to enter a creative";
 }

this didn't work either. Can someone advise me on what is the correct way to fix this.

Thanks,
 Yusef

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Serrin
Top achievements
Rank 1
answered on 30 Jan 2009, 05:43 PM
Hello Yusef,

I think the problem comes from trying to set a string to the .Value when .SelectedItem is actually null.  Since there is no selected item, you can't get a value from it.  You can try something like:

string SelectionItem;  
 
if (RadComboBox1.SelectedItem == null)  
{  
    SelectionItem = "No selection";  
}  
else  
{  
    SelectionItem = RadComboBox1.SelectedItem.Value;  
}  
 
RadTextBox1.Text = SelectionItem

Which first tests for whether there is a selected item, if not we return a "No selection" message, if so we return the value.
0
Toni
Top achievements
Rank 1
answered on 30 Jan 2009, 06:36 PM
Thanks that worked.
Tags
ComboBox
Asked by
Toni
Top achievements
Rank 1
Answers by
Serrin
Top achievements
Rank 1
Toni
Top achievements
Rank 1
Share this question
or