-3

I have a DropDownList which is populated using a sqldatasource, i.e., from database and their is a grid view which is populated with another sqldatasource connected to using the value of dropdownlist.

But it does not execute the query dynamically. I want that whenever the value of dropdownlist changes, the grid view should update. Code please..

akshaykumar6
  • 2,147
  • 4
  • 18
  • 31

3 Answers3

4

ASPX code

<asp:DropDownList id="ddlCountry" AutoPostBack="True" runat="server" OnSelectedIndexChanged="ddlCountry_SelectedIndexChanged" ></asp:DropDownList> 

And CS code

protected void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
{
  FillYourGridviewHere();
}
sajanyamaha
  • 3,119
  • 2
  • 26
  • 44
1
<asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="SqlDataSource2" DataTextField="ssn" DataValueField="ssn" 
         AutoPostBack=true>
    </asp:DropDownList>

This Worked. Thank You.!!

akshaykumar6
  • 2,147
  • 4
  • 18
  • 31
-2

You can just write the dynamic code for populating the grid into a function and bind that function to the dropdownlist onChange event.

Say "mydropdown" is the id of your dropdownlist and "dochanges" is a function that executes your dynamic codes. So you just need to bind the dochanges function to the change event of your dropdownlist.

    $('#mydropown').bind('change',function(){
            dochanges(); //call the dynamic function where you update your grid
    });
  • Is not mention anywhere jQuery, and this code need jQuery library to work. And also in asp.net this can be done using the `OnSelectedIndexChanged` and the `AutoPostBack`. Also this id will not work, you need to use the `mydropdown.ClientID` ~ – Aristos Dec 12 '12 at 07:00
  • thankyou @Aristos .. I just mentioned an aliter way to do that in jQuery. – Mohamed Haseel Dec 12 '12 at 07:21
  • But the one in the question is not use it. – Aristos Dec 12 '12 at 07:33