从dropownlist中选择名称,相关ID出现在文本框中

时间:2018-01-25 13:07:07

标签: c# asp.net

这是我用客户名称填充下拉列表的代码。

 protected void Page_Load(object sender, EventArgs e)
    {
        //Creating a connection to my database using the connection string
        string cs = System.Configuration.ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString;
        SqlConnection con = new SqlConnection(cs);
        {

            SqlCommand cmd = new SqlCommand("Select CustomerName from Customer", con);
            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
            {
                DataTable dt = new DataTable();
                da.Fill(dt);


                DropDownList1.DataTextField = "CustomerName";

                DropDownList1.DataSource = dt;
                DropDownList1.DataBind();
            }
        }
   }
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
    {

    }
}

我也希望能够;从下拉列表框中选择此名称时,关联的客户ID将显示在文本框中。

谢谢!

1 个答案:

答案 0 :(得分:-1)

它的外观应该就这么简单:

<input id="myInput" placeholder="search query">
<div id="myDiv">
  <input type="checkbox" id="box1">
  <label for="box1">Stuff 1</label>
  <input type="checkbox" id="box2">
  <label for="box2">Stuff 2</label>
  <br>
  <input type="checkbox" id="box3">
  <label for="box3">Stuff 3</label>
  <input type="checkbox" id="box4">
  <label for="box4">Stuff 4</label>
</div>

假设您有一个ID为protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e) { TextBox1.Text = DropDownList1.SelectedValue } 的文本框。

或者,如果您想显示下拉列表中的文本(而不是ID值),那么只需:

TextBox1