簡體   English   中英

將下拉列表中選擇的值獲取到字符串變量C#中

[英]Getting the value selected from drop down list into a string variable c#

static public String Titl;    

現在以簡單的編程語言假設我在表單上有一個下拉列表。 當我調試時,我發現寫時ID為dropdownlist1的dropdowlist

dropdownlist1.text; 

包含我在下拉菜單中選擇的值。 但是,當我做這樣的事情:

titl = dropdownlist1.text;    

我沒有在titl變量中獲取值。 需要幫助。 謝謝!

如果您要輸入文字,請選中此選項。

 title=dropdownlist1.selecteditem.text;

如果你想要價值,那么

  title=dropdownlist1.selecteditem.value;
int selectedIndex=dropdownlist1.SelectedIndex;//get index
string selectedText=dropdownlist1.SelectedItem.Text;//get text
string selectedValue=dropdownlist1.SelectedItem.Value;//get value
 Title = !string.IsNullorEmpty(dropdownlist1.SelectedItem.Text) ?
 dropdownlist1.SelectedITem.Text : "";
 Titl = dropdownlist1.SelectedValue;

作品! 謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM