We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to avoid passing extra data added to JSON DataSource from inherited Base class?


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
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Please sign in to access our KB

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon