Using C# & Mysql
I have combobox & button in my webpage, if i select a value from the combobox, then i click the button the page is refreshing, combobox value is changing.
For Example
Combobox value: 1, 2, 3, 4 .....
If i selected 2 then i press the button, webpage is refreshing, combobox values is display from: 1, 2, 3, 4....
Combobox should display 2
Why combobox is displaying a selected value when i press the button.
Table Name: user
Name username
Raja 1
Ravi 2
Ram 3
kumar 4
...,
Button click event code
cmd1 = new OdbcCommand("Select name from users where username = '" + combobox1.Items[combobox1.SelectedIndex].Text + "' ", dbcon);
dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{
textbox1.Text = dr1.GetString(0);
}
dr1.Close();
The Above code is working, but if i select the value 2 from the combobox, then i press the button textbox should display ravi, but textbox is displaying Raja, and also combobox also refreshing, combobox is not displaying 1 instead of 2.
How to solve this issue.
Need C# code Help
Understanding ASP.NET View State might be a useful read. Generally, you need to somehow store the entered values and restore then on page load.
Given the fact that the button is reloading the entire page, wouldn't it be more efficient to reload just a part of it instead?
Just use combobox1.SelectedIndex or SelectedText
instead of the one you used. May be it resolves your issue
也许您正在页面加载中填充dropdownlist,所以一定要在!Page.IsPostBack中填充dropdownlist,我认为这是您的问题
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.