Listbox control does not pass the selected value when clicked
Hi,
I am trying to work the delete role example in chapter 16. Just as an exercise, I'm trying to get the role clicked in the listbox deleted from the list. However, the list box doesn't return the selected value.
Here is my code:
<code>
<%@PageLanguage="C#" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scriptrunat="server">
protected void Page_Load(object sender, EventArgs e)
{
Page.SetFocus(TextBox1);
ListBoxDataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Roles.CreateRole(TextBox1.Text.ToString());
ListBoxDataBind();
TextBox1.Text = "";
}
protected void ListBoxDataBind()
{
ListBox1.DataSource = Roles.GetAllRoles();
ListBox1.DataBind();
}
protected void DeleteButton_Click(object sender, EventArgs e)
{
if (ListBox1.SelectedValue != "")
{
Roles.DeleteRole(ListBox1.SelectedValue);
ListBoxDataBind();
}
}
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Role Manager</title>
</head>
<body>
<formid="form1"runat="server">
<h1>Role Manager</h1>
<b>Add Role:</b><br/>
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<p><asp:ButtonID="Button1"runat="server"Text="Add Role to Application"OnClick="Button1_Click"/></p>
<b>Roles Defined:</b><br/>
<asp:ListBoxID="ListBox1"runat="server"></asp:ListBox>
<p><asp:ButtonID="DeleteButton"runat="server"Text="Delete Role"OnClick="DeleteButton_Click"/></p>
</form>
</body>
</html>
</code>
Any help will be appreciated.
flashmanTom
__________________
Thomas G Magaro
Last edited by flashmanTom; July 6th, 2011 at 12:14 PM..
|