RadCombo nullReferenceException

3 posts, 1 answers
  1. Toni
    Toni avatar
    7 posts
    Member since:
    Mar 2008

    Posted 29 Jan 2009 Link to this post

    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. Answer
    Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 30 Jan 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Toni
    Toni avatar
    7 posts
    Member since:
    Mar 2008

    Posted 30 Jan 2009 Link to this post

    Thanks that worked.
Back to Top