Greetings all. This question is two-fold. I've got a repeater which lists staff members names, current security role, and a dropdown of available security roles. Each person is only allowed one role at a time. The purpose of the page is to allow an admin to change the roles of the staff members....which is where my questions come in.
1st - As you can see in the code below, I'm trying to display the dropdown lists with the person's current security role as the default listitem. I'm clearly not doing this correctly b/c I'm getting an error saying "Literal content ('<asp:listitem Value="') is not allowed within a 'System.Web.UI.WebControls.ListItemCollection'". -- Anyone know how I might handle this?
2nd - What I'd really like to do is let the admin go through all the staff members, select the desired security roles from the drop downs, then click a submit button which updates the 'access_level' field for each member in the 'staff' table. -- Can anyone show me how to do this?
Here's the complete code for the page:
<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
Dim strConnect As String = ConfigurationSettings.AppSettings("ConnectionString")
MyCommand = New SqlDataAdapter("SELECT Firstname, Lastname, id, access_level FROM staff", strConnect)
DS = New DataSet()
MyCommand.Fill(DS, "staff")
MyRepeater.DataSource = DS.Tables("staff").DefaultView
MyRepeater.DataBind()
End Sub
</script>
<form runat="server">
<ASP:Repeater id="MyRepeater" runat="server"> <HeaderTemplate>
<table width="65%" border="0" cellpadding="1" cellspacing="0" bgcolor="#333333">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr bgcolor="cccccc">
<td>Name</td>
<td>Current Access Level</td>
<td>Access Level Options</td>
</tr></HeaderTemplate>
<ItemTemplate>
<tr bgcolor="efefef">
<td><%# DataBinder.Eval(Container.DataItem, "firstname") %> <%# DataBinder.Eval(Container.DataItem, "lastname") %></td>
<td><font color="#999999"><%# DataBinder.Eval(Container.DataItem, "access_level") %></font></td>
<td>
<asp
ropDownList id="DropDownList1" runat="server">
<asp:listitem Value="<%# DataBinder.Eval(Container.DataItem, "id") %>" Text="<%# DataBinder.Eval(Container.DataItem, "access_level") %>" />
<asp:ListItem Value="4" Text="No Access" />
<asp:ListItem Value="1" Text="Contributor" />
<asp:ListItem Value="2" Text="Power User" />
<asp:ListItem Value="3" Text="Site Administrator" />
</asp
ropDownList>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td colspan="3" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" name="update" value="Save Changes"></td>
</tr>
</table>
</td>
</tr>
</table></FooterTemplate>
</ASP:Repeater>
</form>
1st - As you can see in the code below, I'm trying to display the dropdown lists with the person's current security role as the default listitem. I'm clearly not doing this correctly b/c I'm getting an error saying "Literal content ('<asp:listitem Value="') is not allowed within a 'System.Web.UI.WebControls.ListItemCollection'". -- Anyone know how I might handle this?
2nd - What I'd really like to do is let the admin go through all the staff members, select the desired security roles from the drop downs, then click a submit button which updates the 'access_level' field for each member in the 'staff' table. -- Can anyone show me how to do this?
Here's the complete code for the page:
<%@ Page Language="vb" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<script runat="server">
Sub Page_Load(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyCommand As SqlDataAdapter
Dim strConnect As String = ConfigurationSettings.AppSettings("ConnectionString")
MyCommand = New SqlDataAdapter("SELECT Firstname, Lastname, id, access_level FROM staff", strConnect)
DS = New DataSet()
MyCommand.Fill(DS, "staff")
MyRepeater.DataSource = DS.Tables("staff").DefaultView
MyRepeater.DataBind()
End Sub
</script>
<form runat="server">
<ASP:Repeater id="MyRepeater" runat="server"> <HeaderTemplate>
<table width="65%" border="0" cellpadding="1" cellspacing="0" bgcolor="#333333">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr bgcolor="cccccc">
<td>Name</td>
<td>Current Access Level</td>
<td>Access Level Options</td>
</tr></HeaderTemplate>
<ItemTemplate>
<tr bgcolor="efefef">
<td><%# DataBinder.Eval(Container.DataItem, "firstname") %> <%# DataBinder.Eval(Container.DataItem, "lastname") %></td>
<td><font color="#999999"><%# DataBinder.Eval(Container.DataItem, "access_level") %></font></td>
<td>
<asp
<asp:listitem Value="<%# DataBinder.Eval(Container.DataItem, "id") %>" Text="<%# DataBinder.Eval(Container.DataItem, "access_level") %>" />
<asp:ListItem Value="4" Text="No Access" />
<asp:ListItem Value="1" Text="Contributor" />
<asp:ListItem Value="2" Text="Power User" />
<asp:ListItem Value="3" Text="Site Administrator" />
</asp
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
<tr>
<td colspan="3" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td colspan="3" align="right"><input type="submit" name="update" value="Save Changes"></td>
</tr>
</table>
</td>
</tr>
</table></FooterTemplate>
</ASP:Repeater>
</form>