|
-
Mar 25th, 2003, 07:11 AM
#1
Thread Starter
Member
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?
-
Mar 25th, 2003, 08:12 AM
#2
Hyperactive Member
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>
-
Mar 25th, 2003, 08:17 AM
#3
Thread Starter
Member
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
-
Mar 25th, 2003, 10:20 AM
#4
Hyperactive Member
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!
-
Mar 27th, 2003, 07:21 PM
#5
Thread Starter
Member
thanks thought i think i didn't workfor my case..
maybe is something wrong with my code... can anyone please help me ?
-
Apr 4th, 2003, 11:38 AM
#6
Registered User
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
-
Apr 14th, 2003, 10:17 AM
#7
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|