简体   繁体   English

组合框选择值问题

[英]Combobox selecting value problem

In my webpage I am using combobox & searchbutton. 在我的网页中,我正在使用组合框和搜索按钮。

When i select a value from combobox then i click the search button, the combobox first matching value is displaying 当我从组合框中选择一个值时,我单击搜索按钮,则显示组合框的第一个匹配值

For Example 例如

  • combobox values are - 001, 002, 003 组合框的值是-001、002、003
  • When i select the value in the combobox -003 当我在组合框-003中选择值时
  • Then i click the search button 然后我点击搜索按钮
  • The page is refreshing and 001 values are displaying instead of 003 页面正在刷新并且显示001值而不是003

Code for Search Click button: 搜索代码单击按钮:

cmd2 = new OdbcCommand("Select * from table where id = '" + combobox1.Text + "' ", con);
ada2 = new OdbcDataAdapter(cmd2);
ds1 = new DataSet();
ada2.Fill(ds1);
gridview1.DataSource = ds1;
gridview1.DataBind();

How can I solve this issue? 我该如何解决这个问题?

Are you binding your gridview or combobox in your Page_Load method? 您是否在Page_Load方法中绑定了gridview或组合框? I have a hunch this may be the issue. 我预感这可能是问题。 Make sure it looks like this: 确保它看起来像这样:

void Page_Load(Object obj, EventArgs e)
{
  if (!IsPostBack){
     //do your stuff
  }
}

It could be just a typo but it looks like you are selecting the combobox text and not the selectedvalue of the combo box. 它可能只是一个错字,但看起来您正在选择组合框文本,而不是组合框的selectedValue。 Is that correct? 那是对的吗?

您是否尝试过combobox1.SelectedItem.ToString()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM