如何从下拉列表中选择价值? [英] How to select value from dropdown?

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

问题描述

我正在尝试从下拉列表中选择值,但每次只选择第一个值可能是原因。


我的代码是



protected void Page_Load(object sender,EventArgs e)

{

Bugtracker objddl = new Bugtracker();



DataSet ds = objddl.GetTeamMember();

DropDownList1.DataSource = ds;

DropDownList1.DataTextField =TM_Name;

DropDownList1.DataBind();

}





点击按钮



protected void Button1_Click(object sender,EventArgs e)

{



DataSet ds = new DataSet();

SqlConnection con = new SqlConnection();

con.ConnectionString = ConfigurationManager.ConnectionStrings [BugTrackerConnection]。ConnectionString;

SqlCommand cmd = new SqlCommand(select * from Te am_members其中TM_Name ='+ DropDownList1.SelectedItem.Text +',con);



SqlDataAdapter da = new SqlDataAdapter(cmd);

da.Fill(ds);

}

I am trying to select value from dropdown but its selecting only first value every time what could be the reason.

my code is

protected void Page_Load(object sender, EventArgs e)
{
Bugtracker objddl=new Bugtracker();

DataSet ds = objddl.GetTeamMember();
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "TM_Name";
DropDownList1.DataBind();
}


on button click

protected void Button1_Click(object sender, EventArgs e)
{

DataSet ds=new DataSet();
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["BugTrackerConnection"].ConnectionString;
SqlCommand cmd= new SqlCommand("select * from Team_members where TM_Name='"+DropDownList1.SelectedItem.Text+"'",con);

SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(ds);
}

推荐答案

试试这个

try this
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)

{
Bugtracker objddl=new Bugtracker(); 
DataSet ds = objddl.GetTeamMember();
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "TM_Name";
DropDownList1.DataBind();
}

}





用于重播任何查询。



for any query hit to replay.


取决于你的代码

TM_Name ='+ DropDownList1.SelectedItem.Text +'

selectedItem是仅打印选定的下拉项.....





你需要什么,你想从下拉列表中获取所有项目???
depend on your code
TM_Name='"+DropDownList1.SelectedItem.Text+"'"
selectedItem is print only selected dropdown items.....


what is your need, do you want to get all items from dropdown list ???


这篇关于如何从下拉列表中选择价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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