<%@ Page Language="C#" AutoEventWireup="true"%>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
string[] birds = {
"sourcecodernp",
"Delhi",
"Mumbai",
"Jalandhar",
"Bareilly",
"Agra"
};
ListBox1.DataSource = birds;
ListBox1.DataBind();
ListBox1ListBox1.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>
<!DOCTYPE html>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
string[] birds = {
"sourcecodernp",
"Delhi",
"Mumbai",
"Jalandhar",
"Bareilly",
"Agra"
};
ListBox1.DataSource = birds;
ListBox1.DataBind();
ListBox1ListBox1.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>
No comments:
Post a Comment