Thursday, October 25, 2012

Accessing selected item from combo box wen items are added dynamically using List item


using System.Web.UI.WebControls;


//add items to combobox

 comboBox1.Items.Clear();
            List dataBundles = getDataVodacomDataBundles();
            //Value="UDB75MB">Data Bundle 75MB (R88.00)<
            foreach (sp_GetProductDataBundlesResult dataEntry in dataBundles)
            {
                string tssProductBundleValue = String.Format("{0:C0}", dataEntry.TSSProductBundleValue);
                String text = dataEntry.TSSProductBundleName + "(" + tssProductBundleValue + ")";
                String value = "" + dataEntry.TSSProductBundleMegs;
           
                ListItem li = new ListItem(text, value);
                comboBox1.Items.Add(li);
            }


string selectedVAL= ((System.Web.UI.WebControls.ListItem)(comboBox1.SelectedItem)).Value;

No comments:

Post a Comment