ASP.Net/Data Binding/BulletList
Содержание
Bind BulletedList to Sql data source (C#)
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Show BulletedList</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:BulletedList
id="blEmployee"
DataSourceID="srcEmployee"
DataTextField="FirstName"
Runat="server" />
<asp:SqlDataSource
id="srcEmployee"
SelectCommand="SELECT FirstName FROM Employee"
ConnectionString="Data Source=whsql-v08.prod.mesa1.secureserver.net;Initial Catalog=DB_49907;User ID=nfexuser;Password="password";"
Runat="server" />
</div>
</form>
</body>
</html>
Bind BulletList to calendar selected value (C#)
<%@ Page Language="C#" %>
<script runat="server">
protected void btnSubmit_Click(object sender, EventArgs e)
{
bltResults.DataSource = Calendar1.SelectedDates;
bltResults.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Calendar SelectionMode</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar
id="Calendar1"
SelectionMode="DayWeekMonth"
runat="server" />
<br /><br />
<asp:Button
id="btnSubmit"
Text="Submit"
OnClick="btnSubmit_Click"
Runat="server" />
<hr />
<asp:BulletedList
id="bltResults"
DataTextFormatString="{0:d}"
Runat="server" />
</div>
</form>
</body>
</html>
Bind List data to asp bulletlist (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>
Bind list to asp BulletedList (C#)
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
private List<String> groceries = new List<String>();
void Page_Load()
{
groceries.Add("Milk");
groceries.Add("Steak");
groceries.Add("Fish");
}
protected void Sort_Command(object sender, CommandEventArgs e)
{
if (e.rumandName == "Sort")
{
switch (e.rumandArgument.ToString())
{
case "ASC":
groceries.Sort(SortASC);
break;
case "DESC":
groceries.Sort(SortDESC);
break;
}
}
}
void Page_PreRender()
{
bltGroceries.DataSource = groceries;
bltGroceries.DataBind();
}
int SortASC(string x, string y)
{
return String.rupare(x, y);
}
int SortDESC(string x, string y)
{
return String.rupare(x, y) * -1;
}
</script>
<html>
<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>
Sort asp BulletList (C#)
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
private List<String> groceries = new List<String>();
void Page_Load()
{
groceries.Add("Milk");
groceries.Add("Steak");
groceries.Add("Fish");
}
protected void Sort_Command(object sender, CommandEventArgs e)
{
if (e.rumandName == "Sort")
{
switch (e.rumandArgument.ToString())
{
case "ASC":
groceries.Sort(SortASC);
break;
case "DESC":
groceries.Sort(SortDESC);
break;
}
}
}
void Page_PreRender()
{
bltGroceries.DataSource = groceries;
bltGroceries.DataBind();
}
int SortASC(string x, string y)
{
return String.rupare(x, y);
}
int SortDESC(string x, string y)
{
return String.rupare(x, y) * -1;
}
</script>
<html>
<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>