爱问知识人 爱问教育 医院库

c#里dropdownlist和Textbox关联的问题!

首页

c#里dropdownlist和Textbox关联的问题!


        

提交回答
好评回答
  • 2008-11-30 17:35:00
      usingSystem;usingSystem。Data;usingSystem。Configuration;usingSystem。Collections;usingSystem。Web;usingSystem。Web。Security;usingSystem。
      Web。UI;usingSystem。Web。UI。WebControls;usingSystem。Web。UI。WebControls。WebParts;usingSystem。Web。UI。HtmlControls;usingSystem。
      Data。SqlClient;publicpartialcla {protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidButton1_Click(objectsender,EventArgse){stringConnString="server=。
      ;database=service;userid=sa;pwd=";SqlConnectionconn=newSqlConnection(ConnString);SqlCommandcomm=newSqlCommand();comm。Connection=conn;conn。
      Open();if(TextBox8。Text==""){Response。Write("<script>alert('客户姓名不能为空!')</script>");}else{comm。CommandText="select*fromsuopeiwherespr='"+TextBox8。
      Text+"'";SqlDataAdaptersda=newSqlDataAdapter(comm);DataSetds=newDataSet();sda。Fill(ds);if(ds。Tables[0]。Rows。Count>0){this。
      DropDownList1。DataSource=ds;this。DropDownList1。DataValueField="spid";//selectvaluethis。DropDownList1。DataTextField="";//selecttext对应的数据库字段,下拉框显示的值,自己确定this。
      DropDownList1。DataBind();}else{Response。Write("<script>alert('不存在该客户的信息,请核对后重新输入!')</script>");}conn。Close();}}protectedvoidDropDownList1_SelectedIndexChanged(objectsender,EventArgse){SqlConnectionconn=newSqlConnection(ConnString);stringpid=DropDownList1。
      SelectedValue;SqlCommandcomm=newSqlCommand();comm。Connection=conn;conn。Open();comm。CommandText="select*fromsuopeiwherespid="+pid;SqlDataReadersdr=comm。
      ExecuteReader();if(sdr。Read()){Label2。Text=sdr["djrq"]。ToString();Label9。Text=sdr["spid"]。ToString();Label11。Text=sdr["clxh"]。
      ToString();TextBox5。Text=sdr["spyy"]。ToString();TextBox6。Text=sdr["cljg"]。ToString();TextBox7。Text=sdr["khyj"]。ToString();Label12。
      Text=sdr["slr"]。ToString();}sdr。Close();conn。Close();}}。

    z***

    2008-11-30 17:35:00

其他答案

    2008-12-01 12:47:00
  • DropDownList1.SelectedValue = sdr["spid"].ToString(); 这里你写错了,你是要将查询出来的ID号绑定到DropDownList中去,DropDownList1.SelectedValue这个方法肯定不行,你可以这样:DropDownList1.Items.Add(sdr["spid"].ToString());后面的就没有错了~~

    x***

    2008-12-01 12:47:00

  • 2008-11-30 23:11:00
  • 用户名 和 保单 是 1对多所以 select * from tablename where 用户名 = 'x' 这个弄出来的数据读取器应该是多个数据所以应该用while(sdr.Read()){     DropDownList1.Items.Add(sde["字段"].ToString);}这个是绑定,然后当选择项改变的时候重新根据这个值搜索。因为不了解你的数据库所以不好具体说大概就是 select * from tablename where id ='xxx'id代表的表单应该是唯一的 读出来就可以了。

    r***

    2008-11-30 23:11:00

  • 2008-11-30 22:24:00
  •   在TextChanged函数中执行就行啦,我做了一个textbox输入数据回车后就可以更新DropDownlist里的数据。如果要及时显示,不回车,就用ajax就行啦,加个ScriptManager和UpdatePanel就可以啦。using System;using System。
      Data;using System。Configuration;using System。Web;using System。Web。Security;using System。Web。UI;using System。Web。UI。WebControls;using System。
      Web。UI。WebControls。WebParts;using System。Web。UI。HtmlControls;using System。Data。OracleClient;public partial class _Default : System。
      Web。UI。Page { protected void Page_Load(object sender, EventArgs e) { } protected void TextBox1_TextChanged(object sender, EventArgs e) { if (TextBox1。
      Text != "") { string conn_str = "Data Source=****;user=**;password=**"; using (OracleDataAdapter oda = new OracleDataAdapter("select a。
      times from tb_test a where tel='123'", conn_str)) { DataTable dt = new DataTable(); oda。
      Fill(dt); for (int i = 0; i < dt。Rows。Count; i++) { DropDownList1。Items。
      Add(dt。Rows[i][0]。ToString()); } } } }}不知道是否对你有用~~~~。

    l***

    2008-11-30 22:24:00

类似问题

换一换

相关推荐

正在加载...
最新问答 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):