Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have to make a dropdown list in wihch i have to add 5 entries when i select one entry and press search button then it will show all the result against that value and show in gridview.
please help me to do it.
Posted
Updated 18-Apr-13 20:17pm
v2
Comments
Karthik Harve 19-Apr-13 2:20am    
[Edit] pre tags removed

1 solution

C#
//for Drop down list
string sql = "";//put your sql query
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sql, cn);
        da.Fill(ds);

        if (ds.Tables[0].Rows.Count > 0)
        {
            ddl.DataSource = ds;
            ddl.DataTextField = "Name";
            ddl.DataValueField = "id";
            ddl.DataBind();  
       } 

//for button click
 protected void ibtnSearch_Click(object sender, ImageClickEventArgs e)
{
   string searchTXt=ddlComments.SelectedValue.ToString();
   
       string sql = "";//put your sql query
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sql, cn);
        da.Fill(ds);

        if (ds.Tables[0].Rows.Count > 0)
        {
                Gridview.DataSource = ds;
                Gridview.DataBind();  
       } 
}
 
Share this answer
 
v2
Comments
Karthik Harve 19-Apr-13 2:20am    
[Edit] added code block with pre tags.
fak_farrukh 19-Apr-13 2:25am    
sant osha in your code the values of dropdownlist are coming from database??
Sant Osha 19-Apr-13 2:30am    
yes. How you want?
fak_farrukh 19-Apr-13 2:34am    
but if i want to hard code these values??
Sant Osha 19-Apr-13 2:36am    
then go to design view and the values one by one.
OR
in code behind
use following code:
string[] abc={"a","b","c","d"};
ddlComments.Items.AddRange(abc);

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