When the DataSource for a DropDownList control is bound from a Derived class, then the generated JSON DataSource has some extra values as shown in the following screenshot:
Figure 1: Extra values
The reason there are extra values in the JSON DataSource of the DropDownList control is because the DataSource is defined from a Derived class. In general, when an object is created for a Derived class, it includes the public properties, methods, and variables from its Base class.
In order to overcome this issue, define the DataSource for the DropDownList control only with values that are to be bound with the DropDownList fields. That is, when you bind the DataSource from a Derived class having multiple data objects from the Base class, you have to extract the specifically required data to be mapped in the control fields. Generate a filtered data list from the Derived class to bind the DropDownList DataSource by using the Select() method.
To bind the DataTextField and DataValueField, generate a data list source from the corresponding class as given in following code.
CodeBehind - C#
Now, the browser page source has no extra data as shown in the following screenshot:
Figure 2: browser page source without extra data
Control is rendered as follows:
Figure 3: Control
|Article ID:||Published Date:||Last Revised Date:||Platform:||Control:|
|5092||06/01/2015||06/01/2015||ASP.NET Web Forms||General|
or the page will be automatically redirected to sign-in page in 10 seconds.