选择下拉列表项时出现问题....... [英] problem on selecting Dropdownlist items..........

查看:74
本文介绍了选择下拉列表项时出现问题.......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我选择Dropdownlist项目时,它会将所有相关项目数据显示到列表框中
但是当我从下拉列表中选择特定项目时,我想显示只是显示
仅特定项目数据

有人告诉我这是我的代码....



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();



        }

推荐答案

qry = "select full_name from Players";


请将dropdownlist selectedvalue作为where子句传递给查询.然后是特定的结果集olny fetch.


Please pass the Dropdownlist selectedvalue to the query as where clause . Then particular result set olny fetch.


您需要为此修改查询.您没有在查询中包含WHERE子句.查询看起来像

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



并且您需要向代码中添加SqlParameter,如



and you need to add a SqlParameter to your code like

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



当然,where查询中的参数可能会根据您所用的表结构而有所不同.

如果可以提供,我可以为您提供进一步的帮助.



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.


这篇关于选择下拉列表项时出现问题.......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆