Change Gridview Datasource with DropDownList

lakhi
lakhi used Ask the Experts™
on
My application utilizes several gridviews and I wondered if, rather than having separate pages. it would be possible to change the sqldatasource on the page based on a choice selected from a dropdownlist? The fields will all be the same. The selection criteria is all that will change.
If it's possible, could I possibly get an example? Do I trigger the change using  "SelectedIndexChanged"?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
OnSelectedIndexChanged(... )
{
   if( Index == 1)
    {
          GridView1.DataSource= DataSourceObject1;
          GridView1.DataBind();
    }
    else if( Index == 2)
   {
        GridView1.DataSource= DataSourceObject2;
          GridView1.DataBind();
   }

}

try like this
Much clearly

try with this
protected void ddl_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (((DropDownList)sender).SelectedValue  == "1")
        {
            Grid1.DataSource = objDataSource1;
            Grid1.DataBind();
        }
        else if (((DropDownList)sender).SelectedValue == "2")
        {
            Grid1.DataSource = objDataSource2;
            Grid1.DataBind();
        }
    }

Author

Commented:
Thanks so much. That should do it!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial