开发者

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
  • When i select the value in the combobox -003
  • Then i click the search button
  • The page is refreshing and 001 values are displaying instead of 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? 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. Is that correct?


Have you tried with combobox1.SelectedItem.ToString() ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜