分类：电脑/网络-互联网
问题：c#里dropdownlist和Textbox关联的问题！ 
回答：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();}}