首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

DropDownList有关问题

2012-01-16 
DropDownList问题在页面中放三个控件,一个DropDownList,从数据库中绑定,一个TextBox和Button,我要实现,输

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();
[解决办法]
这是不行的.你点按钮后都没处理插入数据库的代码.

热点排行