Click here to Skip to main content
15,884,020 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I create One Webform with one dropdownlist in that i have items like(India,usa,austrlia) when i am click on india i want the details about india at the runtime from database without going another page.
Posted
Updated 22-Dec-13 0:58am
v2
Comments
[no name] 20-Dec-13 3:11am    
So what is the issue here?
Nelek 21-Dec-13 5:59am    
JoCodes 22-Dec-13 6:58am    
No Google to search?

You can do that in SelectedIndexChanged event of the dropdown. Make sure you set AutoPostback property (of the dropdown) to true as well.
Here is a good example of SelectedIndexChanged event http://www.ezineasp.net/post/ASP-Net-DropDownList-OnSelectedIndexChanged-Event.aspx[^]
 
Share this answer
 
Steps

  1. Define SelectedIndexChanged Event for the DropDownList
  2. Inside the Event, connect to Database, create a SqlCommand or SqlDataAdapter and provide the query you want to execute taking the DropDownList's SelectedValue
  3. Execute the Command by ADO.NET methods like ExecuteReader, ExecuteNonQuery, ExecuteScalar or ExecuteXMLReader
  4. Get the results and populate those on required controls
 
Share this answer
 
Place a grid view control in your page and write a function to load gridview like following
public void loadgrid()
{
      SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM [tablename] where [columnname] ='"+DropDownList1.SelecetedValue+"'", connStr); // Change query as per your requirement
            DataSet ds = new DataSet();
            da.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
}
 

Set autopostback property of Dropdownlist to true and then call the above function  in DropDownList1_SelectedIndexChanged Event as follows

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        loadgrid();
    }
 
Share this answer
 
Comments
Karthik_Mahalingam 21-Dec-13 7:53am    
good... would be easier for the OP, if you put the entire ADO.NET code to get the data... or some preferred link..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900