主題が少し奇妙かもしれないことは知っていますが、私の目標を正確に説明する方法がわかりませんでした
コンテンツ管理システムでロールベースの権限を実行しようとしています。これを行うために私が考えることができる最善の方法は、データベースからロールのリストを取得し、それらをCheckBoxListに配置することです。そこから、チェックした値のコンマ区切りの文字列をデータベースのページの詳細に保存します。最後に、ページがプルアップされたら、カンマ区切りの文字列をプルダウンしてString()に分割し、値をループして、現在のユーザーに権限があるかどうかを確認します。
私が懸念しているのは、CheckBoxListをループして値を文字列に変換すると、loopメソッドが文字列の最後にコンマを追加することです...次に、データベースに保存する前にコンマを削除する必要があります。
私の質問は、保存する前に文字列に戻って末尾のコンマを削除する必要がないように、これを行うためのより良い方法はありますか?
''# 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