asp.net listbox attributes
listbox-attributes.aspx
<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
string[] birds = {
"Siberian Jay",
"European Magpie",
"Azure-winged Magpie",
"Spotted Nutcracker",
"Red-billed Blue Magpie",
"Alpine Chough"
};
ListBox1.DataSource = birds;
ListBox1.DataBind();
ListBox1.Rows = ListBox1.Items.Count;
}
for (int i = 0; i < ListBox1.Items.Count; i++)
{
if (i % 2 == 0)
{
ListBox1.Items[i].Attributes.Add("style", "color:red;background-color:lightpink");
}
else
{
ListBox1.Items[i].Attributes.Add("style", "color:seagreen;background-color:beige");
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>asp.net listbox attributes</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
asp.net example - listbox attributes
</h2>
<hr width="550" align="left" color="Gainsboro" />
<br /><br />
<asp:ListBox
ID="ListBox1"
runat="server"
AutoPostBack="true"
Font-Size="X-Large"
SelectionMode="Multiple"
Font-Names="Comic Sans MS"
>
</asp:ListBox>
</div>
</form>
</body>
</html>
- How to set ListBox alternate item text and background color
- How to apply alternating row color in a ListBox
- How to show horizontal ScrollBar in a ListBox
- How to get ListBox multiple selected items
- How to set default selected items in a ListBox
- How to disable specific items in a ListBox
- How to check whether an item exists in a ListBox
- How to create a horizontal CheckBoxList
- How to show ScrollBar in a CheckBoxList
- How to set the maximum limit of selection in a CheckBoxList