Get List Box Selected Value And Get List Box Selected Text

Get List Box Selected Value from Listbox,

  1. public static string GetListBoxSelectedValue(ListBox Listbox1)  
  2. {  
  3.     string selectedItem = "";  
  4.     if (Listbox1.Items.Count > 0) {  
  5.         for (int i = 0; i < Listbox1.Items.Count; i++) {  
  6.             if (Listbox1.Items[i].Selected) {  
  7.                 if (selectedItem == "") {  
  8.                     selectedItem = Listbox1.Items[i].Value;  
  9.                     break;  
  10.                 }  
  11.             }  
  12.         }  
  13.     }  
  14.     return selectedItem;  
  15. }  
Get List Box Selected Text,

  1. public static string GetListBoxSelectedText(ListBox Listbox1) {  
  2.     string selectedItem = "";  
  3.     if (Listbox1.Items.Count > 0) {  
  4.         for (int i = 0; i < Listbox1.Items.Count; i++) {  
  5.             if (Listbox1.Items[i].Selected) {  
  6.                 if (selectedItem == "") {  
  7.                     selectedItem = Listbox1.Items[i].Text;  
  8.                     break;  
  9.                 }  
  10.             }  
  11.         }  
  12.     }  
  13.     return selectedItem;  
  14. }