Results 1 to 7 of 7

Thread: problem with radio button list and drop down list (not combo)

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    38

    problem with radio button list and drop down list (not combo)

    i am facing a few problem...
    first i have a dropdown list
    next i have a radio button list

    now the question is how i arrange the items in the drop down list in alphabetical order?

    another question is how i store the value for radion button list in a session object?

  2. #2
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    Just sort your data source the way you want before binding to it.

    Ex. if it's coming from the DB, do an ORDER BY with your SQL.

    You can also use a SortedList.

    Re. the session variables. You can still save stuff that way just like you would in ASP using Session(<variable>) = <Value>

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    38
    i am using a for loop for retriving the items..
    here are the codes.. maybe u can help me..
    thanks

    Dim ds As DataSet
    ds = New DataSet()
    MyDataProvider.Fill(ds, "c:\inetpub\wwwroot\quicknames\AtoZ.mdb", "AtoZ")

    Dim strAdd As String
    Dim i As Integer
    Dim j As Integer
    Dim bAdd As Boolean
    For i = 0 To ds.Tables(0).Rows.Count - 1

    strAdd = ds.Tables(0).Rows(i)(3)

    'check if list already contain strAdd
    bAdd = True
    For j = 0 To DropDownList2.Items.Count - 1
    If (DropDownList2.Items(j).Text = strAdd) Then
    bAdd = False
    Exit For
    End If
    Next

    If (bAdd = True) Then
    DropDownList2.Items.Add(strAdd)
    End If

    Next

  4. #4
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    I don't know how useful this will be as I don't use the
    DataAdapter or DataSets very much and then my code also targets SQL instead
    of Access... But anyways here's how I would do it...

    Unless you are using the dataset for other purposes
    it looks like it could be overkill for loading up the dropdown...

    You want to weed out duplicate entries and also sort them, which
    you can accomplish with a SQL statement like:

    Code:
    Dim szSQL as string = "SELECT DISTINCT <columnname> FROM [AtoZ] ORDER BY <columnname>"
    Now run the query and bind it to the dropdown.
    Code:
            Dim myConn As New System.Data.SqlClient.SqlConnection(<your connecttiopn string>)
    
            myConn.Open()
    
            Dim myCmd As New System.Data.SqlClient.SqlCommand(szSQL, myConn)
    
            Dim dr As SqlClient.SqlDataReader = myCmd.ExecuteReader()
    
            DropDownList2.DataSource = dr
            DropDownList2.DataTextField = "<columnname>"
            DropDownList2.DataBind()
    
            dr.Close()
            myConn.Close()
    You will need to use OleDbCommand, OleDbConnection... instead of the SQL specific ones..

    Hope this helps at leats a bit!

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2003
    Posts
    38
    thanks thought i think i didn't workfor my case..
    maybe is something wrong with my code... can anyone please help me ?

  6. #6
    Registered User
    Join Date
    Apr 2003
    Location
    Columbia, SC
    Posts
    1
    fungi has it right. A datareader is more efficient if all you are doing is populating comboboxes and grids, etc.

    Post your code and indicate where the error is.

    Thanks,
    Greg

  7. #7
    Lively Member
    Join Date
    Aug 2002
    Location
    outerspace
    Posts
    126
    You could use a dataView to sort your data maybe.
    "All those who wonder are not lost" -j.r.r tolkien

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width