DropDownList问题

qpg184926 2007-02-28 03:19:24
在页面中放三个控件,一个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();
}
我都试了,这样写不行,请高手帮忙
...全文
167 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hqpy 2007-03-01
  • 打赏
  • 举报
回复
DropDownList1.Text=TextBox3.Text.ToString().Trim();
Free_Windy 2007-03-01
  • 打赏
  • 举报
回复
这是不行的.你点按钮后都没处理插入数据库的代码.

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧