ASP.Net/Asp Control/BulletedList
Содержание
Add item to asp bulletlist
<%@ Page Language="VB" %>
<script runat="server">
Sub Page_Load()
For i As Integer = 1 To 100
bltList.Items.Add("Item " & i.ToString())
Next
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<style type="text/css">
html
{
background-color:silver;
}
.contents
{
background-color:white;
width:200px;
height:200px;
}
</style>
<title>Panel ScrollBars</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel
id="pnlContent"
ScrollBars="Auto"
CssClass="contents"
Runat="server">
<asp:BulletedList
id="bltList"
Runat="server" />
</asp:Panel>
</div>
</form>
</body>
</html>
BulletedList display Mode: hyper link
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show BulletedList HyperLinks</title>
</head>
<body>
<form id="form1" runat="server">
<asp:BulletedList
id="blWebsites"
DisplayMode="HyperLink"
Target="_blank"
Runat="server">
<asp:ListItem
Text="Yahoo"
Value="http://www.Yahoo.ru" />
<asp:ListItem
Text="Google"
Value="http://www.Google.ru" />
<asp:ListItem
Text="nfex.ru"
Value="http://www.nfex.ru" />
</asp:BulletedList>
</form>
</body>
</html>
Change BulletedList style
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Bullet styles:<br />
<br />
<asp:BulletedList BulletStyle="Numbered"
DisplayMode="LinkButton"
ID="BulletedList1"
OnClick="BulletedList1_Click"
runat="server">
</asp:BulletedList>
</div>
</form>
</body>
</html>
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
foreach (string style in
Enum.GetNames(typeof(BulletStyle)))
{
BulletedList1.Items.Add(style);
}
}
}
protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
{
string styleName = BulletedList1.Items[e.Index].Text;
BulletStyle style = (BulletStyle)Enum.Parse(typeof(BulletStyle), styleName);
BulletedList1.BulletStyle = style;
}
}
Sort asp BulletList in VB.net
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
Private groceries As New List(Of String)()
Sub Page_Load()
groceries.Add("Milk")
groceries.Add("Steak")
groceries.Add("Fish")
End Sub
Sub Sort_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
If e.rumandName = "Sort" Then
Select Case e.rumandArgument.ToString()
Case "ASC"
groceries.Sort(AddressOf SortASC)
Case "DESC"
groceries.Sort(AddressOf SortDESC)
End Select
End If
End Sub
Sub Page_PreRender()
bltGroceries.DataSource = groceries
bltGroceries.DataBind()
End Sub
Function SortASC(ByVal x As String, ByVal y As String) As Integer
Return String.rupare(x, y)
End Function
Function SortDESC(ByVal x As String, ByVal y As String) As Integer
Return String.rupare(x, y) * -1
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Button Command</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button
id="btnSortAsc"
Text="Sort ASC"
CommandName="Sort"
CommandArgument="ASC"
OnCommand="Sort_Command"
Runat="server" />
<asp:Button
id="btnSortDESC"
Text="Sort DESC"
CommandName="Sort"
CommandArgument="DESC"
OnCommand="Sort_Command"
Runat="server" />
<br /><br />
<asp:BulletedList
id="bltGroceries"
Runat="server" />
</div>
</form>
</body>
</html>