DropDownList问题
在页面中放三个控件,一个DropDownList,从数据库中绑定,一个TextBox和Button,我要实现,输入TextBox的值后点Button,然后DropDownList中就自动选中我刚在TextBox中输入的那一项,代码如下:
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string sql="select gcmc from gc";
DB myDB=new DB();
DataTable myTable=myDB.SearchDT(sql);
DropDownList1.DataSource=myTable;
DropDownList1.DataTextField="gcmc";
DropDownList1.DataValueField="gcmc";
DropDownList1.DataBind();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
DropDownList1.SelectedValue=TextBox3.Text.ToString().Trim();
//DropDownList1.SelectedItem.Text=TextBox3.Text.ToString().Trim();
//DropDownList1.SelectedItem.Value=TextBox3.Text.ToString().Trim();
}
我都试了,这样写不行,请高手帮忙