C#新手求解 修改数据时联动菜单的操作 在线等

huitian1621 2011-10-09 06:06:13
有一个DropDownList控件,其他都是TextBox控件,我在DropDownList中选择数据之后,其他控件怎么绑定数据库中对应的数据呢?
求方法,代码更好
...全文
36 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
huitian1621 2011-10-10
  • 打赏
  • 举报
回复

protected void DropDownList_AlarmPersonID_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["DB_CON"].ConnectionString;
sqlcon.Open();
SqlCommand sqlcom = new SqlCommand();
sqlcom.Connection = sqlcon;
sqlcom.CommandText = "select * from Alarm_List where Alarm_PersonID = " + DropDownList_AlarmPersonID.Text;
sqlcom.CommandType = CommandType.Text;
SqlDataAdapter sqlda = new SqlDataAdapter(sqlcom);
ds = new DataSet();
sqlda.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
TextBox_AlarmPersonName.Text = ds.Tables[0].Rows[0][1].ToString();
TextBox_AlarmPhone.Text = ds.Tables[0].Rows[0][2].ToString();
}
}


这样写怎么没效果呢,高手帮忙看看
huitian1621 2011-10-09
  • 打赏
  • 举报
回复
那我用SelectedIndexChanged事件里写查询?这样可以吗?
huitian1621 2011-10-09
  • 打赏
  • 举报
回复
那我要新建一个数据源,还有什么别的方法么? 用一个隐藏的textbox和button,进行刷新写入dropdownlist与之对应的值,这个方法也可以,但是我不想再加控件了,如果只能绑定数据源那我就试试吧。
beyond_me21 2011-10-09
  • 打赏
  • 举报
回复
在DropDownList的OnChanged事件里绑定其它控件的数据源

28,408

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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