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

troubles reading datatextfield of selected item

1 Answer 57 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
DrGiorgini
Top achievements
Rank 1
DrGiorgini asked on 26 Apr 2017, 10:45 AM

Hi,
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";
ddlArticle.DataBind();

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.

 

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 01 May 2017, 08:50 AM
Hi,

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:
http://demos.telerik.com/aspnet-ajax/grid/examples/functionality/filtering/filter-templates/defaultcs.aspx

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:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/changing-the-grid-structure-dynamically-on-postback

I hope this will prove helpful.

Regards,
Eyup
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.
Tags
DropDownList
Asked by
DrGiorgini
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or