Need help on ObjectDataSource control...

Posted on 2009-06-29
Last Modified: 2012-05-07
Is there a way to programmatically call the ObjectDataSource control based on certain selection made in a dropdownlist? Please see code below. When the option with value "kickass" is selected from dropdownlist "ddlMovieCategory", I want to display another dropdownlist for user to select.  All other options will just call the ObjectDataSource (id="srcMovies").  Please provide sample code.

Thanks very much in advance!

Web Form Code:

    <form id="form1" runat="server">


    Please select a movie category: 







    Runat="server" /> 



        ID="dlMovies" CssClass="dataView" 





        <%#Eval("MovieDesc")%><br />













            ControlID="ddlMovieCategory" />







    protected void Page_Load(object sender, EventArgs e)


        if (!IsPostBack)


            // Call to the function to populate dropdownlist from xml





    // Populates the dropdownlist from xml file

    private void PopulateDDLFromXMLFile()


        DataSet ds = new DataSet();



        // Get the dataview of table "Category", which is default table name

        DataView dv = ds.Tables["Category"].DefaultView;

        // Or we can use:

        // DataView dv = ds.Tables[0].DefaultView;


        // Now sort the DataView vy column name "Name"

        dv.Sort = "Name";


        // Now define datatext field and datavalue field of dropdownlist

        ddlMovieCategory.DataTextField = "Name";

        ddlMovieCategory.DataValueField = "ID";


        // Now bind the dropdownlist to the dataview

        ddlMovieCategory.DataSource = dv;



    protected void ddlMovieCategory_SelectedIndexChanged(object sender, EventArgs e)


        //do something here



XML File That Populates Dropdown:

<?xml version="1.0" encoding="utf-8" ?>































Open in new window

Question by:WebAppDeveloper
1 Comment
LVL 29

Accepted Solution

David H.H.Lee earned 500 total points
ID: 24742779
Hi WebAppDeveloper,
>>..programmatically call the ObjectDataSource control based on certain selection made in a dropdownlist
You can call ObjectDataSource's onselected event to handle the required condition as needed.
Check the details here:


public void ObjectDataSource1_Selected(object source, ObjectDataSourceStatusEventArgs e)
    if (e.ReturnValue != null)
        //continue your logic here, probably re-bind a resource to another dropdownlist based on selected...

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Events in static methods 3 50
Memory Usage 2 50
C# HTTP GET method sample code 3 40
Windows Media Player 2 10
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now