Hi there.
I know the subject might be a little strange, but I wasn't sure how to exactly describe my goal
I'm trying to do some Role based permissions in a content management system. The best way I can think of to do this is to pull the list of roles from the database and place them in a CheckBoxList. From there, I save a comma separated string of the checked values into the page details of the database. Finally when the page is pulled back up, I check if the current User has permission by pulling down the comma separated string and splitting it into a String() and loop through the values.
The concern I have is that when I loop through the CheckBoxList and convert the values to a string, the loop method adds a comma to the end of the string... I then have to strip the comma before saving it to the database.
My question is, is there a better way of doing this so that I don't have to go back into the string and strip the trailing comma before saving?
'this is to get all selected items from
'a checkboxlist and add it to a string
'the reason for this is to insert the final string
'into a database for future retrieval.
Dim i As Integer
Dim sb As StringBuilder = New StringBuilder()
For i = 0 To CheckBoxList1.Items.Count - 1
If CheckBoxList1.Items(i).Selected Then
sb.Append(CheckBoxList1.Items(i).Value & ",")
End If
Next
'now I want to save the string to the database
'so I first have to strip the comma at the end
Dim str As String = sb.ToString.Trim(",")
'Then save str to the database
'I have now retrieved the string from the
'database and I need to now add it to a One Dimensional String()
Dim str_arr() As String = Split(str, ",")
For Each s As String In str_arr
'testing purposes only
Response.Write(s & " -</br>")
'If User.IsInRole(s) Then
' Do Stuff
'End If
Next