我想從DropDownList中顯示不同的標籤輸出,按鈕下拉列表標記輸出C#
select Item on DropDownList and click button to show output in label
誰能幫我這個?
我想從DropDownList中顯示不同的標籤輸出,按鈕下拉列表標記輸出C#
select Item on DropDownList and click button to show output in label
誰能幫我這個?
protected void Button1_Click(object sender, EventArgs e)
{
lable1.Text=DropDownList1.SelectedValue.ToString();
}
或U可以做
protected void Button1_Click(object sender, EventArgs e)
{
String input=DropDownList1.SelectedIndex >= 0 ? DropDownList1.SelectedItem.ToString() : "";
lable1.Text=input;
}
剛剛寫下這button click event
protected void Button1_Click(object sender, EventArgs e) {
label.text = ComboBox.SelectedText;
}
Ÿ-1可以downvoter解釋什麼是錯在這.... –
「你可以使用SelectedText屬性來檢索或更改ComboBox控件中當前選定的文本。但是,您應該知道,由於用戶交互,選擇可能會自動更改。例如,如果您在按鈕Click事件處理程序中檢索SelectedText值,則該值將是一個空字符串。這是因爲當輸入焦點從組合框移動到按鈕時,選擇會自動清除。'。此外,OP要求這與一個DropDownList,而不是一個組合框控件... – dtsg
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = DropDownList1.SelectedValue;
}
操作需要做的操作按鈕點擊不在更改.. –
如果它工作標記爲你的答案。所以這對其他人有用。 –