views:

36

answers:

1

How do I dynamically change the content of a data grid to select the correct data from database when the drop down list SelectedIndexChanged event happens?

To be more specific, I have a dropdown list of apple, orange and pearl.

When the dropdown list changes from apple to orange, I want the datagrid to query the database like this "select count(*) from fruit where name='orange'" and dynamically update the content.

+2  A: 

Try this one also make surethat your DropDownList1 have the AutoPostBack property set to true

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        MyDatabaseDataContext mydb = new MyDatabaseDataContext();
        var x = from y in mydb.MyTable
                where y.myField == DropDownList1.SelectedItem.Text
                select y;
        GridView1.DataSource = x;
        GridView1.DataBind();
    }
Raymund