Click here to Skip to main content
14,453,349 members
Rate this:
Please Sign up or sign in to vote.
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);
            ListBox1.DataSource = ds;
            ListBox1.DataTextField = "full_name";

Updated 21-Jun-12 4:47am
Rate this:
Please Sign up or sign in to vote.

Solution 1

qry = "select full_name from Players";

Please pass the Dropdownlist selectedvalue to the query as where clause . Then particular result set olny fetch.
Rate this:
Please Sign up or sign in to vote.

Solution 2

You need to modify the query for that. You have not included the WHERE clause in the query. The query would look like

SELECT full_name FROM Players WHERE id = @id

and you need to add a SqlParameter to your code like

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.

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100