Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i select Dropdownlist items it is showing all related items data into listbox
but i want to show when i select on particular item from Dropdownlist just show
particular item data only

any one tell me this is my code....



protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            qry = "select full_name from Players";
           
            con = new SqlConnection(connection);
            cmd = new SqlCommand(qry, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            ListBox1.DataSource = ds;
            ListBox1.DataTextField = "full_name";
            ListBox1.DataBind();



        }
Posted
Updated 21-Jun-12 3:47am
v2

SQL
qry = "select full_name from Players";

Please pass the Dropdownlist selectedvalue to the query as where clause . Then particular result set olny fetch.
 
Share this answer
 
You need to modify the query for that. You have not included the WHERE clause in the query. The query would look like

SQL
SELECT full_name FROM Players WHERE id = @id


and you need to add a SqlParameter to your code like

C#
cmd.Parameters.Add(new SqlParameter("@id", DropDownList1.SelectedValue));


Of course, the parameters in the where query could vary depending upon the table structure in your case.

If you can provide it, I can help you further.
 
Share this answer
 
v2

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