When an option in the listbox is clicked, it is displayed in the textbox. This needs to change the property AutoPostBack of the listbox to true
Add code to the Selectedindexchanged event of the listbox
if(this.ListBox1 .SelectedItem !=null )
{
this.textbox.text=this.listbox1.selecteditem.text;
}
When there are two listboxes, the first is the type of the second, and the content of the second is displayed in the textbox
if (this.ListBox1.SelectedValue == "TeacherId")//teacherid is the value of the option in listbox1
{
ListBox2.Items.Clear(); //First clear listbox2 to remove redundant content
string strSQL = "SELECT TeacherId,TeacherName FROM teacher_infotable;";
DataSet ds = db.GetDataSet(strSQL);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
ListItem lt = new ListItem();
lt.Value = dt.Rows[i].ItemArray[0].ToString();
lt.Text = dt.Rows[i].ItemArray[1].ToString();
this.ListBox2.Items.Add(lt);
}
}
}
Event code for listbox2
foreach (ListItem li in ListBox2.Items)
{
if (li.Selected)
{
this.txt_MessageClassIdentifier.Text += li.Value +",";
}
}
The effect is as follows; here is the ID, not the text, adjust it according to your needs