troubles reading datatextfield of selected item

2 posts, 0 answers
  1. DrGiorgini
    DrGiorgini avatar
    11 posts
    Member since:
    Jul 2010

    Posted 26 Apr 2017 Link to this post

    I have problems retrieving the text of a raddropdownlist.
    I populate the ddl in a quite basic way (Articles is a datatable):

    ddlArticle.DataSource = Articles;
    ddlArticle.DataTextField = "Description";
    ddlArticle.DataValueField = "CodArt";

    Changing the selected value triggers nothing.
    A button near the ddl triggers some events (basically, a databind on a radgrid); at this time i need to read datatextfield and datavaluefield:

    string opv = ddlArticle.SelectedValue;
    string articlename = ddlArticle.SelectedItem.Text;

    ddlArticle.SelectedValue works perfectly and opv really contains the selected value, but ddlArticle.SelectedItem.Text throws an exception:

    Exception thrown: 'System.NullReferenceException' in App_Web_prodotto.aspx.11948b1e.cmqcknjt.dll ("Object reference not set to an instance of an object.")

    So i tried another way:

    string opv = ddlArticle.SelectedValue;
    RadComboBoxItem Item = ddlArticle.FindItemByValue(opv);
    string article = Item.Text;

    Again, opv contains the correct value, but Item.text is null, and Item is null too.

    I am using Telerik 2016.3.

    Thank you for any help you can provide.


  2. Eyup
    Eyup avatar
    3407 posts

    Posted 01 May 2017 Link to this post


    You can try accessing the item during later stage of the page life cycle, for example PreRender. If you will filter the grid records on dropdown change, you need to remove the AutoPostBack property and use the filter method:

    If you plan to change structure of the grid upon selection change, you can follow the steps demonstrated in the following article how to do that:

    I hope this will prove helpful.

    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top