读书人

DropDownList有关问题

发布时间: 2012-01-16 23:36:51 作者: rapoo

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();
}
我都试了,这样写不行,请高手帮忙

[解决办法]
DropDownList1.Text=TextBox3.Text.ToString().Trim();
[解决办法]
这是不行的.你点按钮后都没处理插入数据库的代码.

读书人网 >C#

热点推荐