L
Lance Wynn
Hi all,
I have been working on this seeming simple problem the better part of the
morning, and can't seem to figure it out.
I have a listbox as a template:
<asp:TemplateField HeaderText="Roles" SortExpression="Roles">
<EditItemTemplate>
<asp:ListBox ID="ListBox1" runat="server" AppendDataBoundItems="True"
DataSourceID="SqlRoleSource" DataTextField="RoleName"
DataValueField="RoleName" SelectionMode="Multiple">
<asp:ListItem Value="*">Allow All</asp:ListItem>
</asp:ListBox>
</EditItemTemplate>
</asp:TemplateField>
It is bound to a Datasource that queries all the Roles from my application
security. When editing, I want it to highlight all the Roles that the user
belongs to.
I was experimenting with something like the following, but I can never
access anything but the ListItems that are hard coded into the template,
none of the bound items seem to be accessible:
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
If DetailsView1.CurrentMode = DetailsViewMode.Edit Or
DetailsView1.CurrentMode = DetailsViewMode.Insert Then
Dim listbox1 As ListBox = DetailsView1.FindControl("ListBox1")
For Each item As ListItem In listbox1.Items
'Logic for selecting item here if the user belongs to the role.
Next
End If
End Sub
Can anyone tell me what I am missing please?
Thank You
Lance
I have been working on this seeming simple problem the better part of the
morning, and can't seem to figure it out.
I have a listbox as a template:
<asp:TemplateField HeaderText="Roles" SortExpression="Roles">
<EditItemTemplate>
<asp:ListBox ID="ListBox1" runat="server" AppendDataBoundItems="True"
DataSourceID="SqlRoleSource" DataTextField="RoleName"
DataValueField="RoleName" SelectionMode="Multiple">
<asp:ListItem Value="*">Allow All</asp:ListItem>
</asp:ListBox>
</EditItemTemplate>
</asp:TemplateField>
It is bound to a Datasource that queries all the Roles from my application
security. When editing, I want it to highlight all the Roles that the user
belongs to.
I was experimenting with something like the following, but I can never
access anything but the ListItems that are hard coded into the template,
none of the bound items seem to be accessible:
Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
If DetailsView1.CurrentMode = DetailsViewMode.Edit Or
DetailsView1.CurrentMode = DetailsViewMode.Insert Then
Dim listbox1 As ListBox = DetailsView1.FindControl("ListBox1")
For Each item As ListItem In listbox1.Items
'Logic for selecting item here if the user belongs to the role.
Next
End If
End Sub
Can anyone tell me what I am missing please?
Thank You
Lance