• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

pulling multiple dropdown values

does anyone know how to pull selected item values.......and  values is the keyword from a dropdownlist?

I can use a request.form("fieldVal"), but that only pulls the id values of the field, not the text associated with the id.  If we're talking about displaying values on pageB based on what the user selected on pageA.

0
shuittny
Asked:
shuittny
2 Solutions
 
riyasjefCommented:
Like this

DropDownList1.SelectedItem.Text;

RJ
0
 
ViggeeCommented:
u cant take the selecteditems text to a new page with the same control name.

have a text box and with the onchange event of the combo box, assign the textbox with the selected item's text to it. then u can get the selecteditem's text in the new page.

in ur codebehind page add this to the DropDownList1

DropDownList1.Attributes.Add("onChange", "document.Form1.TextBox1.value = document.Form1.DropDownList1[document.Form1.DropDownList1.selectedIndex].text;");

Viggee
0
 
b1xml2Commented:
you question brings up a fundamental issue:
1. If you are passing values from one form to another and are not using Server.Transfer, Viggee's solution may apply.
2. However, you are providing a point in which things can be broken. Because you are providing both the id and value loosely and expect it to work.

It is better if at all possible, to store the list in the cache object and make it available:


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
b1xml2Commented:
VB.NET
====
Imports System.Web.Caching
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web

Public NotInheritable Class ReferenceData
      Private _instance As ReferenceData
      
      Public Enum ReferenceDataList
            Countries
            Languages
      End Enum
      
      Private Sub New()
      End Sub
            
      Public Shared ReadOnly Property Instance() As ReferenceData
            Get
                  If _instance Is Nothing Then
                        _instance = New ReferenceData()
                  End If
                  Return _instance
            End Get
      End Property
      
      Private ReadOnly Property MyCache() As Cache
            Get
                  Return HttpContext.Current.Cache
            End Get
      End Property
      
      Default ReadOnly Property Items(ByVal item As ReferenceDataList) As DataTable
            Get
                  Dim name As String = item.ToString()
                  If MyCache(name) Is Nothing Then
                        MyCache.Insert(name,GetValues(item),Nothing,DateTime.Now.AddDays(1),Cache.NoSlidingExpiration,CacheItemPriority.High,Nothing)
                  End If
                  Return DirectCast(MyCache(name),DataTable).Copy()
                  
            End Get            
      End Property
      
      Private Function GetValues(ByVal item As ReferenceDataList) As DataTable
            Dim connection As New SqlConnection(..)
            'assuming stored procedure has the naming convention sp<item_name>
            Dim adapter As New SqlDataAdapter("EXEC sp" & item.ToString(),connection)
            Dim table As New DataTable
            connection.Open()
            adapter.Fill(table)
            connection.Close()
            adapter.Dispose()
            return table
      End Function
      
      Public ReadOnly Property Countries() As DataTable
            Get
                  Return Me(ReferenceDataList.Countries)
            End Get
      End Property
      
      Public ReadOnly Property Languages() As DataTable
            Get
                  Return Me(ReferenceDataList.Languages)
            End Get
      End Property
      
      

End Class

C#
===
using System;
using System.Web.Caching;
using System.Data;
using System.Data.SqlClient;
using System.Web;

public sealed class ReferenceData
{
      private ReferenceData _instance;
      
      public enum ReferenceDataList
      {
            Countries,
            Languages
      }
      
      public ReferenceData() {}
            
      public static ReferenceData Instance
      {
            get
            {
                  if (_instance == null)
                        _instance= new ReferenceData();
                  
                  return _instance;
            }
      }
      
      private Cache MyCache
      {
            get { return HttpContext.Current.Cache; }
      }
      
      public DataTable this[ReferenceDataList item]
      {
            get
            {
                  string name = item.ToString();
                  if (MyCache[name] == null)
                  {
                        MyCache.Insert(name,GetValues(item),null,DateTime.Now.AddDays(1),Cache.NoSlidingExpiration,CacheItemPriority.High,null);
                  }
                  
                  return ((DataTable)MyCache[name]).Copy();
            }
      }
      
      private DataTable GetValues(ReferenceDataList item)
      {
            SqlConnection connection = new SqlConnection(..);
            SqlDataAdapter adapter = new SqlDataAdapter("EXEC sp" + item.ToString(),connection);
            DataTable table = new DataTable();
            connection.Open();
            adapter.Fill(table);
            connection.Close();
            adapter.Dispose();
            return table;
      }
      
      public DataTable Countries
      {
            get { return this[ReferenceDataList.Countries]; }
      }
      
      public DataTable Languages
      {
            get { return this[ReferenceDataList.Languages]; }
      }
      
}

      
      
      
0
 
b1xml2Commented:
Thus you can do it this way
C#
DataRow[] rows = ReferenceData.Instance.Countries.Select(string.Format("COUNTRY_CODE = '{0}'","UK"));
if (rows != null && rows.Length == 1)
{
  return rows[0]["COUNTRY_NAME"].ToString();
}

VB.NET
====
Dim rows As DataRow() = ReferenceData.Instance.Countries.Select(string.Format("COUNTRY_CODE = '{0}'","UK"))
If Not rows Is Nothing AndAlso rows.Length = 1 Then
  Return rows(0)("COUNTRY_NAME").ToString
End If

You can extend the ReferenceData class accordingly,
0
 
shuittnyAuthor Commented:
http://authors.aspalliance.com/das/tutorial/listbox.aspx

I scrolled to 'Selecting Items In a Listbox'

That site has everything that I'm looking for.  I'm able to pull values (the text that the user views on a listbox) from a listbox and then set that value to a hidden text field then submit the values to another page
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now