ASP.NET Web Forms - 執行個體
下一篇:ASP.NET Web Forms參考手冊之——HTML 伺服器控件
上一篇:ASP.NET Web Forms 自學篇:(十八) 導航
ASP.NET HTML 控件
1.HTML Anchor 跳轉:
<script runat="server">
Sub Page_Load
link1.HRef="https://blog.csdn.net/weixin_43972758/article/details/85319239"
link1.Target="_blank"
link1.Title="HDG首篇"
link2.HRef="https://blog.csdn.net/weixin_43972758/article/details/86523710"
link2.Target="_blank"
link2.Title="ASP.NET MVC"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<a id="link1" runat="server">HDG首篇!</a>
<br>
<a id="link2" runat="server">ASP.NET MVC</a>
</form>
</body>
</html>
運作結果:
HDG首篇!
ASP.NET MVC
2.HTML Button 按鈕:
<script runat="server">
Sub button1(Source As Object, e As EventArgs)
p1.InnerHtml="You clicked the blue button!"
End Sub
Sub button2(Source As Object, e As EventArgs)
p1.InnerHtml="You clicked the pink button!"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<button id="b1" OnServerClick="button1"
style="background-color:#e6e6fa;
height:25;width:100" runat="server">
Blue button!
</button>
<button id="b2"
OnServerClick="button2"
style="background-color:#fff0f5;
height:25;width:100" runat="server">
Pink button!
</button>
<p id="p1" runat="server" />
</form>
</body>
</html>
運作結果:
3.HTML Image 圖檔1:
<script runat="server">
Sub Page_Load(Sender As Object,E As EventArgs)
image1.Src="smiley.gif"
image1.Alt="Smiley"
image1.Border="3"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<img id="image1" runat="server" />
</form>
</body>
</html>
運作結果:
4.HTML Image 2 圖檔2:
<script runat="server">
Sub choose_image(Sender As Object, e As EventArgs)
image1.Src = select1.Value
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<select id="select1" runat="server">
<option value="smiley.gif">Smiley</option>
<option value="angry.gif">Angry</option>
<option value="stickman.gif">Stickman</option>
</select>
<input type="submit" runat="server" value="Display image"
onserverclick="choose_image">
<br><br>
<img id="image1" src="smiley.gif" runat="server" width="32" height="32" />
</form>
</body>
</html>
運作結果:
5.HTML Inputbutton 輸入框:
<script runat="server">
Sub submit(sender As Object, e as EventArgs)
if name.value<>"" then
p1.InnerHtml="Welcome " & name.value & "!"
end if
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Enter your name: <input id="name" type="text" size="30" runat="server" />
<br><br>
<input type="submit" value="Submit" onserverclick="submit" runat="server" />
<p id="p1" runat="server" />
</form>
</body>
</html>
運作結果:
6.HTML InputCheckbox 選擇框:
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
if red.Checked=True then
p1.InnerHtml="You prefer red!"
else
p1.InnerHtml="You prefer blue!"
end if
red.checked=false
blue.checked=false
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
What color do you prefer?
<br>
<input id="red" type="checkbox" runat="server" /> Red
<br>
<input id="blue" type="checkbox" runat="server" /> Blue
<br>
<input type="button" value="Submit" onserverclick="submit" runat="server" />
<p id="p1" runat="server" />
</form>
</body>
</html>
運作結果:
7.HTML InputHidden 輸入 隐藏:
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
hidden1.Value=string1.Value
p1.InnerHtml="Hidden value= " + hidden1.Value
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Enter some text: <input id="string1" type="text" size="25" runat="server" />
<input type="submit" value="Submit" onserverclick="submit" runat="server" />
<input id="hidden1" type="hidden" runat="server" />
<p id="p1" runat="server" />
</form>
</body>
</html>
運作結果:
8.HTML InputImage 圖像框:
<script runat="server">
Sub button1(Source As Object, e As ImageClickEventArgs)
p1.InnerHtml="You clicked the smiley button!"
End Sub
Sub button2(Source As Object, e As ImageClickEventArgs)
p1.InnerHtml="You clicked the angry button!"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<p>Click on one of the images:</p>
<p>
<input type="image" src="smiley.gif"
onserverclick="button1" runat="server" width="32" height="32" />
</p>
<p>
<input type="image" src="angry.gif"
onserverclick="button2" runat="server" width="32" height="32" />
</p>
<p id="p1" runat="server" />
</form>
</body>
</html>
運作結果:
9.HTML InputRadiobutton 單選按鈕框:
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
if r1.Checked=True then
p1.InnerHtml="Your favorite color is red"
else
if r2.Checked=True then
p1.InnerHtml="Your favorite color is green"
else
if r3.Checked=True then
p1.InnerHtml="Your favorite color is blue"
end if
end if
end if
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<p>
Select your favorite color:
<br>
<input id="r1" name="col" type="radio" runat="server">Red</input>
<br>
<input id="r2" name="col" type="radio" runat="server">Green</input>
<br>
<input id="r3" name="col" type="radio" runat="server">Blue</input>
<br>
<input type="button" value="Submit" onserverclick="submit" runat="server" />
<p id="p1" runat="server" />
</form>
</body>
</html>
運作結果:
10.HTML Table 表格1:
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
Dim row,numrows,numcells,j,i
row=0
numrows=cint(rows1.Value)
numcells=cint(cells1.Value)
for j=1 to numrows
Dim r As New HtmlTableRow()
row=row+1
for i=1 to numcells
Dim c As New HtmlTableCell()
c.Controls.Add(New LiteralControl("row " & j & ", cell " & i))
r.Cells.Add(c)
next
t1.Rows.Add(r)
t1.Visible=true
next
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<p>
Table rows:
<select id="rows1" runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<br>Table cells:
<select id="cells1" runat="server">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<br><br>
<input type="submit" value="Display Table" runat="server" onserverclick="submit">
</p>
<table id="t1" border="1" runat="server" visible="false" />
</form>
</body>
</html>
運作結果:
11.HTML Table 2 表2:
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
dim i,j
table1.BGColor="yellow"
table1.BorderColor="red"
for i=0 To table1.Rows.Count-1
for j=0 To table1.Rows(i).Cells.Count-1
table1.Rows(i).Cells(j).InnerHtml="Row " & i
next
next
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<table id="table1" border="1" runat="server">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
<tr>
<td>Cell 3</td>
<td>Cell 4</td>
</tr>
</table>
<br>
<input type="button" value="Change Contents" onserverclick="submit" runat="server" />
</form>
</body>
</html>
運作結果:
12.HTML Textarea 多行文本框:
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
p1.InnerHtml = "<b>You wrote:</b> " & textarea1.Value
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Enter some text:<br>
<textarea id="textarea1" cols="35" rows="6" runat="server" />
<input type="submit" value="Submit" onserverclick="submit" runat="server" />
<p id="p1" runat="server" />
</form>
</body>
</html>
運作結果:
ASP.NET Web 控件
1.AdRotator 廣告控件:
<%
url=Request.QueryString("url")
If url<>"" then Response.Redirect(url)
%>
<!DOCTYPE html>
<html>
<body>
<%
set adrotator=Server.CreateObject("MSWC.AdRotator")
adrotator.TargetFrame="target='_blank'"
response.write(adrotator.GetAdvertisement("text/advertisements.txt"))
%>
<p>
NOTE: Because images are changed randomly, and because this page has few images to choose from, it will
often display the same advertisement twice in a row.
</p>
<p>NOTE: The AdRotator does not work with Internet Information Server 7 (IIS7).</p>
<p>
<a href="text/advertisements.txt">
<img src="/images/btn_view_text.gif">
</a>
</p>
</body>
</html>
運作結果:
2.Button 按鈕控件:
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
button1.Text="You clicked me!"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" />
</form>
</body>
</html>
運作結果:
3.Button 2 按鈕2:
<script runat="server">
Sub submit(Source As Object, e As EventArgs)
button1.Style("background-color")="#0000ff"
button1.Style("color")="#ffffff"
button1.Style("width")="200px"
button1.Style("cursor")="pointer"
button1.Style("font-family")="verdana"
button1.Style("font-weight")="bold"
button1.Style("font-size")="14pt"
button1.Text="You clicked me!"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Button id="button1" Text="Click me!" runat="server" OnClick="submit" />
</form>
</body>
</html>
運作結果:
4.Calendar 月曆1:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Calendar runat="server" />
</form>
</body>
</html>
運作結果:
5.Calendar 2 月曆2
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:calendar daynameformat="Full" runat="server">
<weekenddaystyle backcolor="#fafad2" forecolor="#ff0000" />
<dayheaderstyle forecolor="#0000ff" />
<todaydaystyle backcolor="#00ff00" />
</asp:calendar>
</form>
</body>
</html>
運作結果:
6.Calendar 3 月曆3
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:calendar daynameformat="Full" runat="server"
selectionmode="DayWeekMonth"
selectmonthtext="<*>"
selectweektext="<->" />
<selectorstyle backcolor="#f5f5f5" />
</asp:Calendar>
</form>
</body>
</html>
運作結果:
7.Checkbox 複選框:
<script runat="server">
Sub Check(sender As Object, e As EventArgs)
if check1.Checked then
work.Text=home.Text
else
work.Text=""
end if
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<p>
Home Phone:
<asp:TextBox id="home" runat="server" />
<br>
Work Phone:
<asp:TextBox id="work" runat="server" />
<asp:CheckBox id="check1"
Text="Same as home phone" TextAlign="Right"
AutoPostBack="True" OnCheckedChanged="Check"
runat="server" />
</p>
</form>
</body>
</html>
運作結果:
8.CheckboxList 複選框清單:
<script runat="server">
Sub Check(sender As Object, e As EventArgs)
dim i
mess.Text="<p>Selected Item(s):</p>"
for i=0 to check1.Items.Count-1
if check1.Items(i).Selected then
mess.Text+=check1.Items(i).Text + "<br>"
end if
next
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:CheckBoxList id="check1" AutoPostBack="True"
TextAlign="Right" OnSelectedIndexChanged="Check"
runat="server">
<asp:listitem>Item 1</asp:listitem>
<asp:listitem>Item 2</asp:listitem>
<asp:listitem>Item 3</asp:listitem>
<asp:listitem>Item 4</asp:listitem>
<asp:listitem>Item 5</asp:listitem>
<asp:listitem>Item 6</asp:listitem>
</asp:CheckBoxList>
<br>
<asp:label id="mess" runat="server" />
</form>
</body>
</html>
運作結果:
9.DataList 資料表:
<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycdcatalog=New DataSet
mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
cdcatalog.DataSource=mycdcatalog
cdcatalog.DataBind()
end if
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:DataList id="cdcatalog"
gridlines="Both"
runat="server">
<headertemplate>
My CD Catalog
</headertemplate>
<itemtemplate>
"<%#Container.DataItem("title")%>" of <%#Container.DataItem("artist")%> - $<%#Container.DataItem("price")%>
</itemtemplate>
<footertemplate>
© Hege Refsnes
</footertemplate>
</asp:DataList>
</form>
</body>
</html>
運作結果:
10.用 styles的DataList:
<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycdcatalog=New DataSet
mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
cdcatalog.DataSource=mycdcatalog
cdcatalog.DataBind()
end if
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:DataList id="cdcatalog"
runat="server"
cellpadding="2"
cellspacing="2"
borderstyle="inset"
backcolor="#e8e8e8"
width="100%"
headerstyle-font-name="Verdana"
headerstyle-font-size="12pt"
headerstyle-horizontalalign="center"
headerstyle-font-bold="True"
itemstyle-backcolor="#778899"
itemstyle-forecolor="#ffffff"
footerstyle-font-size="9pt"
footerstyle-font-italic="True">
<headertemplate>
My CD Catalog
</headertemplate>
<itemtemplate>
"<%#Container.DataItem("title")%>" of <%#Container.DataItem("artist")%> - $<%#Container.DataItem("price")%>
</itemtemplate>
<footertemplate>
© Hege Refsnes
</footertemplate>
</asp:DataList>
</form>
</body>
</html>
運作結果:
11.用 < AlternatingItemTemplate>的DataList :
<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycdcatalog=New DataSet
mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
cdcatalog.DataSource=mycdcatalog
cdcatalog.DataBind()
end if
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:DataList id="cdcatalog"
runat="server"
cellpadding="2"
cellspacing="2"
borderstyle="inset"
backcolor="#e8e8e8"
width="100%"
headerstyle-font-name="Verdana"
headerstyle-font-size="12pt"
headerstyle-horizontalalign="center"
headerstyle-font-bold="True"
itemstyle-backcolor="#778899"
itemstyle-forecolor="#ffffff"
alternatingitemstyle-backcolor="#e8e8e8"
alternatingitemstyle-forecolor="#000000"
footerstyle-font-size="9pt"
footerstyle-font-italic="True">
<headertemplate>
My CD Catalog
</headertemplate>
<itemtemplate>
"<%#Container.DataItem("title")%>" of <%#Container.DataItem("artist")%> - $<%#Container.DataItem("price")%>
</itemtemplate>
<alternatingitemtemplate>
"<%#Container.DataItem("title")%>" of <%#Container.DataItem("artist")%> - $<%#Container.DataItem("price")%>
</alternatingitemtemplate>
<footertemplate>
© Hege Refsnes
</footertemplate>
</asp:DataList>
</form>
</body>
</html>
運作結果:
12.DropdownList 下拉清單:
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
mess.Text="You selected " & drop1.SelectedItem.Text
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:DropDownList id="drop1" runat="server">
<asp:listitem>Item 1</asp:listitem>
<asp:listitem>Item 2</asp:listitem>
<asp:listitem>Item 3</asp:listitem>
<asp:listitem>Item 4</asp:listitem>
<asp:listitem>Item 5</asp:listitem>
<asp:listitem>Item 6</asp:listitem>
</asp:DropDownList>
<asp:button text="Submit" onclick="submit" runat="server" />
<p><asp:label id="mess" runat="server" /></p>
</form>
</body>
</html>
運作結果:
13.Hyperlink 超連結:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:hyperlink imageurl="/banners/w6.gif"
navigateurl="https://blog.csdn.net/weixin_43972758/article/details/85319239"
text="Visit W3Cschool!"
target="_blank"
runat="server" />
</form>
</body>
</html>
運作結果:
14.Image 圖檔:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:image runat="server"
alternatetext="靈活大胖子HDG"
imageurl="/banners/w6.gif" />
</form>
</body>
</html>
運作結果:
15.ImageButton 圖檔按鈕:
<script runat="server">
Sub getCoordinates(sender As Object, e As ImageClickEventArgs)
mess.Text="Coordinates: " & e.x & ", " & e.y
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<p>Click on the image:</p>
<asp:imagebutton runat="server"
imageurl="smiley.gif"
onclick="getCoordinates" />
<p><asp:label id="mess" runat="server" /></p>
</form>
</body>
</html>
運作結果:
16.Label 文本:
<script runat="server">
Sub submit(Sender As Object, e As EventArgs)
label1.Text=txt1.Text
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Write some text:
<asp:TextBox id="txt1" Width="200" runat="server" />
<asp:Button id="b1" Text="Copy to Label" OnClick="submit" runat="server" />
<p><asp:Label id="label1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
17.LinkButton 連結按鈕:
<script runat="server">
Sub lblClick(sender As Object, e As EventArgs)
Label1.Text="You clicked the LinkButton control"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:linkbutton text="Click me!" onclick="lblClick" runat="server" />
<p><asp:Label id="Label1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
18.Listbox 清單框:
<script runat="server">
Sub submit(Sender As Object,e As EventArgs)
mess.Text="You selected " & drop1.SelectedItem.Text
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:ListBox id="drop1" rows="3" runat="server">
<asp:listitem selected="true">Item 1</asp:listitem>
<asp:listitem>Item 2</asp:listitem>
<asp:listitem>Item 3</asp:listitem>
<asp:listitem>Item 4</asp:listitem>
<asp:listitem>Item 5</asp:listitem>
<asp:listitem>Item 6</asp:listitem>
</asp:ListBox>
<asp:button text="Submit" onclick="submit" runat="server" />
<p><asp:label id="mess" runat="server" /></p>
</form>
</body>
</html>
運作結果:
19.Literal 文字:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:literal text="I love ASP. NET!" runat="server" />
</form>
</body>
</html>
運作結果:
I love ASP. NET!
20.Literal 2 文字2
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
Literal1.Text="I love ASP.NET!"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Literal id="Literal1" Text="I love ASP!" runat="server" />
<br><br>
<asp:button text="Change Text" onclick="submit" runat="server" />
</form>
</body>
</html>
運作結果:
21.Panel 面闆:
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
if check1.Checked then
panel1.Visible=false
else
panel1.Visible=true
end if
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Panel id="panel1"
runat="server" BackColor="#ff0000"
Height="100px" Width="100px">
Hello World!
</asp:Panel>
<asp:CheckBox id="check1"
Text="Hide Panel control"
runat="server" />
<br><br>
<asp:button text="Reload" runat="server" />
</form>
</body>
</html>
運作結果:
22.Radiobutton 單選按鈕:
<script runat="server">
Sub submit(Sender As Object, e As EventArgs)
if red.Checked then
Label1.Text="You selected " & red.Text
elseIf green.Checked then
Label1.Text="You selected " & green.Text
elseIf blue.Checked then
Label1.Text="You selected " & blue.Text
end if
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Select your favorite color:
<br>
<asp:RadioButton id="red" Text="Red" Checked="True"
GroupName="colors" runat="server" />
<br>
<asp:RadioButton id="green" Text="Green"
GroupName="colors" runat="server" />
<br>
<asp:RadioButton id="blue" Text="Blue"
GroupName="colors" runat="server" />
<br>
<asp:button text="Submit" onclick="submit" runat="server" />
<p><asp:Label id="Label1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
23.RadiobuttonList 單選按鈕清單:
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
label1.Text="You selected " & radiolist1.SelectedItem.Text
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="radiolist1" runat="server">
<asp:listitem selected="true">Item 1</asp:listitem>
<asp:listitem>Item 2</asp:listitem>
<asp:listitem>Item 3</asp:listitem>
<asp:listitem>Item 4</asp:listitem>
</asp:RadioButtonList>
<br>
<asp:button text="Submit" onclick="submit" runat="server" />
<p><asp:Label id="Label1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
24.Repeater 通訊器:
<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycdcatalog=New DataSet
mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
cdcatalog.DataSource=mycdcatalog
cdcatalog.DataBind()
end if
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Repeater id="cdcatalog" runat="server">
<headertemplate>
<table border="1" width="100%">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Company</th>
<th>Price</th>
</tr>
</headertemplate>
<itemtemplate>
<tr>
<td><%#Container.DataItem("title")%> </td>
<td><%#Container.DataItem("artist")%> </td>
<td><%#Container.DataItem("company")%> </td>
<td><%#Container.DataItem("price")%> </td>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:Repeater>
</form>
</body>
</html>
運作結果:
25.用 < AlternatingItemTemplate> 重複:
<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycdcatalog=New DataSet
mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
cdcatalog.DataSource=mycdcatalog
cdcatalog.DataBind()
end if
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Repeater id="cdcatalog" runat="server">
<headertemplate>
<table border="1" width="100%">
<tr>
<th>Title</th>
<th>Artist</th>
<th>Company</th>
<th>Price</th>
</tr>
</headertemplate>
<itemtemplate>
<tr>
<td><%#Container.DataItem("title")%> </td>
<td><%#Container.DataItem("artist")%> </td>
<td><%#Container.DataItem("company")%> </td>
<td><%#Container.DataItem("price")%> </td>
</tr>
</itemtemplate>
<alternatingitemtemplate>
<tr bgcolor="#e8e8e8">
<td><%#Container.DataItem("title")%> </td>
<td><%#Container.DataItem("artist")%> </td>
<td><%#Container.DataItem("company")%> </td>
<td><%#Container.DataItem("price")%> </td>
</tr>
</alternatingitemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:Repeater>
</form>
</body>
</html>
運作結果:
26.用 < SeparatorTemplate>重複:
<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycdcatalog=New DataSet
mycdcatalog.ReadXml(MapPath("cdcatalog.xml"))
cdcatalog.DataSource=mycdcatalog
cdcatalog.DataBind()
end if
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Repeater id="cdcatalog" runat="server">
<headertemplate>
<table border="0" width="100%">
<tr>
<th align="left">Title</th>
<th align="left">Artist</th>
<th align="left">Company</th>
<th align="left">Price</th>
</tr>
</headertemplate>
<itemtemplate>
<tr>
<td><%#Container.DataItem("title")%> </td>
<td><%#Container.DataItem("artist")%> </td>
<td><%#Container.DataItem("company")%> </td>
<td><%#Container.DataItem("price")%> </td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="6"><hr></td>
</tr>
</separatortemplate>
<footertemplate>
</table>
</footertemplate>
</asp:Repeater>
</form>
</body>
</html>
運作結果:
27.Table 表:
<!DOCTYPE html>
<html>
<body>
<form runat=server>
<asp:table runat="server" cellpadding="5"
gridlines="horizontal" horizontalalign="Center">
<asp:tablerow>
<asp:tablecell>1</asp:tablecell>
<asp:tablecell>2</asp:tablecell>
</asp:tablerow>
<asp:tablerow>
<asp:tablecell>3</asp:tablecell>
<asp:tablecell>4</asp:tablecell>
</asp:tablerow>
</asp:table>
<br>
<asp:table runat="server" cellpadding="5"
gridlines="vertical" horizontalalign="Center">
<asp:tablerow>
<asp:tablecell>1</asp:tablecell>
<asp:tablecell>2</asp:tablecell>
</asp:tablerow>
<asp:tablerow>
<asp:tablecell>3</asp:tablecell>
<asp:tablecell>4</asp:tablecell>
</asp:tablerow>
</asp:table>
</form>
</body>
</html>
運作結果:
28.Table 2 表2:
<script runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
dim rows,cells,j,i
rows=3
cells=2
For j=0 To rows-1
dim r As New TableRow()
For i=0 To cells-1
dim c As New TableCell()
c.Controls.Add(New LiteralControl("row " & j & ", cell " & i))
r.Cells.Add(c)
Next
Table1.Rows.Add(r)
Next
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Table id="Table1" BorderWidth="1" GridLines="Both" runat="server" />
</form>
</body>
</html>
運作結果:
29.Textbox 文本框:
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
lbl1.Text="Your name is " & txt1.Text
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:button onclick="submit" text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
30.Textbox 2 文本框2 多行:
<script runat="server">
sub submit(sender As Object, e As EventArgs)
lbl1.Text=txt1.Text
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:TextBox id="txt1" Text="Hello World!"
Font_Face="verdana" BackColor="#0000ff"
ForeColor="white" TextMode="MultiLine"
Height="50" runat="server" />
<asp:button onclick="submit"
text="Copy Text to Label" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
31.Textbox 3 文本框3:
<script runat="server">
Sub change(sender As Object, e As EventArgs)
lbl1.Text="You changed text to " & txt1.Text
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Change text
<asp:TextBox id="txt1" runat="server"
text="Hello World!" ontextchanged="change" autopostback="true" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
32.XML:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:xml documentsource="cdcatalog.xml" transformsource="cdcatalog.xsl" runat="server" />
</form>
<p><a href="cdcatalog.xml" target="_blank">View XML file</a></p>
<p><a href="cdcatalog.xsl" target="_blank">View XSL file</a></p>
</body>
</html>
運作結果:
ASP.NET Validation 控件
1.CompareValidator 比較驗證控件:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<table border="0" bgcolor="#b0c4de">
<tr valign="top">
<td colspan="4"><h4>Compare two values</h4></td>
</tr>
<tr valign="top">
<td><asp:TextBox id="txt1" runat="server" /></td>
<td> = </td>
<td><asp:TextBox id="txt2" runat="server" /></td>
<td><asp:button text="Validate" runat="server" /></td>
</tr>
</table>
<br>
<asp:CompareValidator id="compval"
Display="dynamic"
ControlToValidate="txt1"
ControlToCompare="txt2"
ForeColor="red"
BackColor="yellow"
Type="String"
EnableClientScript="false"
Text="Validation Failed!"
runat="server" />
</form>
</body>
</html>
運作結果:
2.CompareValidator 2 比較驗證控件2:
<script runat="server">
sub check_operator(sender As Object, e As EventArgs)
compval.Operator=CType(list.SelectedIndex,ValidationCompareOperator)
compval.Validate()
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<table border="0" bgcolor="#b0c4de">
<tr valign="top">
<td colspan="4"><h4>Compare two values</h4></td>
</tr>
<tr valign="top">
<td><asp:TextBox id="txt1" runat="server" /></td>
<td>
<asp:ListBox id="list" rows="2" OnSelectedIndexChanged="check_operator" runat="server">
<asp:listitem value="Equal" selected>=</asp:listitem>
<asp:listitem value="NotEqual"><></asp:listitem>
</asp:ListBox>
</td>
<td><asp:TextBox id="txt2" runat="server" /></td>
<td><asp:button text="Validate" runat="server" /></td>
</tr>
</table>
<br>
<asp:CompareValidator id="compval"
Display="dynamic"
ControlToValidate="txt1"
ControlToCompare="txt2"
ForeColor="red"
BackColor="yellow"
Type="String"
EnableClientScript="false"
Text="Validation Failed!"
runat="server" />
</form>
</body>
</html>
運作結果:
3.CustomValidator 自定義驗證控件:
<script runat="server">
Sub user(source As object,args As ServerValidateEventArgs)
if len(args.Value)<8 or len(args.Value)>16 then
args.IsValid=false
else
args.IsValid=true
end if
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:label runat="server" text="Enter a username: " />
<asp:TextBox id="txt1" runat="server" />
<asp:button text="Submit" runat="server" />
<br>
<asp:Label id="mess" runat="server" />
<br>
<asp:customvalidator controltovalidate="txt1"
onservervalidate="user"
text="A username must be between 8 and 16 characters!"
runat="server" />
</form>
</body>
</html>
運作結果:
4.RangeValidator 範圍驗證控件:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Enter a date between 2005-01-01 and 2005-12-31:
<br>
<asp:TextBox id="tbox1" runat="server" />
<br><br>
<asp:button text="Submit" runat="server" />
<br><br>
<asp:rangevalidator controltovalidate="tbox1"
minimumvalue="2005-01-01"
maximumvalue="2005-12-31"
type="Date"
enableclientscript="false"
text="The date must be between 2005-01-01 and 2005-12-31!"
runat="server" />
</form>
</body>
</html>
運作結果:
5.RangeValidator 2 範圍驗證控件2:
<script runat="server">
Sub submit(sender As Object, e As EventArgs)
If Page.IsValid Then
lbl1.Text="Page is valid."
Else
lbl1.Text="Page is not valid!!"
End If
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Enter a number from 1 to 100:
<asp:TextBox id="tbox1" runat="server" />
<br><br>
<asp:button text="Submit" onclick="submit" runat="server" />
<br><br>
<asp:Label id="lbl1" runat="server" />
<br>
<asp:rangevalidator controltovalidate="tbox1"
minimumvalue="1"
maximumvalue="100"
type="Integer"
enableclientscript="false"
text="The value must be from 1 to 100!"
runat="server" />
</form>
</body>
</html>
運作結果:
6.RegularExpressionValidator 正規表達式驗證器:
<script runat="server">
sub submit(sender As Object, e As EventArgs)
if Page.IsValid then
lbl.Text="The page is valid!"
else
lbl.Text="The page is not valid!"
end if
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Enter a US zip code:
<asp:TextBox id="txtbox1" runat="server" />
<br><br>
<asp:button text="Submit" onclick="submit" runat="server" />
<br><br>
<asp:Label id="lbl" runat="server" />
<br>
<asp:regularexpressionvalidator controltovalidate="txtbox1"
validationexpression="\d{5}"
enableclientscript="false"
errormessage="The zip code must be 5 numeric digits!"
runat="server" />
</form>
</body>
</html>
運作結果:
7.RequiredFieldValidator 必填驗證控件:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
Name: <asp:TextBox id="name" runat="server" />
<br>
Age: <asp:TextBox id="age" runat="server" />
<br><br>
<asp:button runat="server" text="Submit" />
<br><br>
<asp:requiredfieldvalidator controltovalidate="name"
text="The name field is required!"
runat="server" />
</form>
</body>
</html>
運作結果:
8.Validationsummary 驗證摘要控件:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<table>
<tr>
<td>
<table bgcolor="#b0c4de" cellspacing="10">
<tr>
<td align="right">Name:</td>
<td><asp:TextBox id="txt_name" runat="server" /></td>
<td>
<asp:requiredfieldvalidator controltovalidate="txt_name"
errormessage="Name"
text="*"
runat="server" />
</td>
</tr>
<tr>
<td align="right">Card Type:</td>
<td>
<asp:RadioButtonList id="rlist_type"
RepeatLayout="Flow"
runat="server">
<asp:listitem>Diners</asp:listitem>
<asp:listitem>MasterCard</asp:listitem>
<asp:listitem>Visa</asp:listitem>
</asp:RadioButtonList>
</td>
<td>
<asp:requiredfieldvalidator controltovalidate="rlist_type"
errormessage="Card Type"
initialvalue=""
text="*"
runat="server" />
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="b1" Text="Submit" runat="server" /></td>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<asp:validationsummary headertext="You must enter a value in the following fields:"
displaymode="BulletList"
enableclientscript="true"
runat="server" />
</form>
</body>
</html>
運作結果:
9.Validationsummary 2 驗證摘要控件2:
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<table>
<tr>
<td>
<table bgcolor="#b0c4de" cellspacing="10">
<tr>
<td align="right">Name:</td>
<td><asp:TextBox id="txt_name" runat="server" /></td>
<td>
<asp:requiredfieldvalidator controltovalidate="txt_name"
errormessage="Name"
text="*"
runat="server" />
</td>
</tr>
<tr>
<td align="right">Card Type:</td>
<td>
<asp:RadioButtonList id="rlist_type"
RepeatLayout="Flow"
runat="server">
<asp:listitem>Diners</asp:listitem>
<asp:listitem>MasterCard</asp:listitem>
<asp:listitem>Visa</asp:listitem>
</asp:RadioButtonList>
</td>
<td>
<asp:requiredfieldvalidator controltovalidate="rlist_type"
errormessage="Card Type"
initialvalue=""
text="*"
runat="server" />
</td>
</tr>
<tr>
<td></td>
<td><asp:Button id="b1" Text="Submit" runat="server" /></td>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
<asp:validationsummary showmessagebox="true"
showsummary="false"
headertext="You must enter a value in the following fields:"
enableclientscript="true"
runat="server" />
</form>
</body>
</html>
運作結果:
ASP.NET 事件
1.Page_Load 頁面加載:
<script runat="server">
Sub Page_Load
lbl1.Text="The date and time is " & now()
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<h3><asp:label id="lbl1" runat="server" /></h3>
</form>
</body>
</html>
運作結果:
2.Page.IsPostBack 首次加載判斷:
<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
lbl1.Text="The date and time is " & now()
end if
End Sub
Sub submit(s As Object, e As EventArgs)
lbl2.Text="Hello World!"
End Sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<h3><asp:label id="lbl1" runat="server" /></h3>
<h3><asp:label id="lbl2" runat="server" /></h3>
<asp:button text="Submit" onclick="submit" runat="server" />
</form>
</body>
</html>
運作結果:
ASP.NET 資料綁定
1.ArrayList RadioButtonList 單選按鈕清單:
<script runat="server">
Sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
rb.DataSource=mycountries
rb.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
2.ArrayList DropDownList ArrayList下拉清單:
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New ArrayList
mycountries.Add("Norway")
mycountries.Add("Sweden")
mycountries.Add("France")
mycountries.Add("Italy")
mycountries.TrimToSize()
mycountries.Sort()
dd.DataSource=mycountries
dd.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & dd.SelectedItem.Text
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:DropDownList id="dd" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
3.Hashtable RadioButtonList 1 哈希表單選按鈕1:
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
4.Hashtable RadiobuttonList 2 哈希表單選按鈕2:
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim navigate=New Hashtable
navigate.Add("RadioButtonList","control_radiobuttonlist.asp")
navigate.Add("CheckBoxList","control_checkboxlist.asp")
navigate.Add("DropDownList","control_dropdownlist.asp")
navigate.Add("ListBox","control_listbox.asp")
rb.DataSource=navigate
rb.DataValueField="Value"
rb.DataTextField="Key"
rb.DataBind()
end if
end sub
sub navigate(s as Object, e As EventArgs)
response.redirect(rb.SelectedItem.Value)
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="navigate" />
</form>
</body>
</html>
運作結果:
5.Hashtable DropDownList 哈希表下拉清單:
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New Hashtable
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
dd.DataSource=mycountries
dd.DataValueField="Key"
dd.DataTextField="Value"
dd.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & dd.SelectedItem.Text
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:DropDownList id="dd" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
6.SortedList RadioButtonList 1 排序清單單選按鈕清單1
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
rb.DataSource=mycountries
rb.DataValueField="Key"
rb.DataTextField="Value"
rb.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
7.SortedList RadiobuttonList 2 排序清單單選按鈕清單2
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim navigate=New SortedList
navigate.Add("RadioButtonList","control_radiobuttonlist.asp")
navigate.Add("CheckBoxList","control_checkboxlist.asp")
navigate.Add("DropDownList","control_dropdownlist.asp")
navigate.Add("ListBox","control_listbox.asp")
rb.DataSource=navigate
rb.DataValueField="Value"
rb.DataTextField="Key"
rb.DataBind()
end if
end sub
sub navigate(s as Object, e As EventArgs)
response.redirect(rb.SelectedItem.Value)
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="navigate" />
</form>
</body>
</html>
運作結果:
8.SortedList DropDownList 排序下拉清單:
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New SortedList
mycountries.Add("N","Norway")
mycountries.Add("S","Sweden")
mycountries.Add("F","France")
mycountries.Add("I","Italy")
dd.DataSource=mycountries
dd.DataValueField="Key"
dd.DataTextField="Value"
dd.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & dd.SelectedItem.Text
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:DropDownList id="dd" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
9.XML RadiobuttonList XML單選按鈕清單:
<%@ Import Namespace="System.Data" %>
<script runat="server">
sub Page_Load
if Not Page.IsPostBack then
dim mycountries=New DataSet
mycountries.ReadXml(MapPath("countries.xml"))
rb.DataSource=mycountries
rb.DataValueField="value"
rb.DataTextField="text"
rb.DataBind()
end if
end sub
sub displayMessage(s as Object,e As EventArgs)
lbl1.text="Your favorite country is: " & rb.SelectedItem.Text
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:RadioButtonList id="rb" runat="server"
AutoPostBack="True" onSelectedIndexChanged="displayMessage" />
<p><asp:label id="lbl1" runat="server" /></p>
</form>
</body>
</html>
運作結果:
ASP.NET 資料庫
1.資料庫連結 - 綁定一個 Repeater 控件:
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/db/northwind.mdb"))
dbconn.Open()
sql="SELECT * FROM customers"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
customers.DataSource=dbread
customers.DataBind()
dbread.Close()
dbconn.Close()
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:Repeater id="customers" runat="server">
<headertemplate>
<table border="1" width="100%">
<tr bgcolor="#b0c4de">
<th>Companyname</th>
<th>Contactname</th>
<th>Address</th>
<th>City</th>
</tr>
</headertemplate>
<itemtemplate>
<tr bgcolor="#f0f0f0">
<td><%#Container.DataItem("companyname")%> </td>
<td><%#Container.DataItem("contactname")%> </td>
<td><%#Container.DataItem("address")%> </td>
<td><%#Container.DataItem("city")%> </td>
</tr>
</itemtemplate>
<footertemplate>
</table>
</footertemplate>
</asp:Repeater>
</form>
</body>
</html>
運作結果:
2.資料庫連結 - 綁定一個 DataList 控件:
<%@ Import Namespace="System.Data.OleDb" %>
<script runat="server">
sub Page_Load
dim dbconn,sql,dbcomm,dbread
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & server.mappath("/db/northwind.mdb"))
dbconn.Open()
sql="SELECT * FROM customers"
dbcomm=New OleDbCommand(sql,dbconn)
dbread=dbcomm.ExecuteReader()
customers.DataSource=dbread
customers.DataBind()
dbread.Close()
dbconn.Close()
end sub
</script>
<!DOCTYPE html>
<html>
<body>
<form runat="server">
<asp:DataList id="customers"
runat="server"
cellpadding="2"
cellspacing="2"
borderstyle="inset"
backcolor="#e8e8e8"
width="100%"
headerstyle-font-name="Verdana"
headerstyle-font-size="12pt"
headerstyle-horizontalalign="center"
headerstyle-font-bold="True"
itemstyle-backcolor="#778899"
itemstyle-forecolor="#ffffff"
footerstyle-font-size="9pt"
footerstyle-font-italic="True">
<headertemplate>
Customers Table
</headertemplate>
<itemtemplate>
<%#Container.DataItem("companyname")%> in
<%#Container.DataItem("address")%>, <%#Container.DataItem("city")%>
</itemtemplate>
<footertemplate>
Source: Northwind Database
</footertemplate>
</asp:DataList>
</form>
</body>
</html>
運作結果:
下一篇:ASP.NET Web Forms參考手冊之——HTML 伺服器控件
上一篇:ASP.NET Web Forms 自學篇:(十八) 導航
友情連結:
ASP.NET MVC零基礎自學篇:(一)ASP.NET MVC簡介
ASP.NET Razor篇——标記
C#将Excel表格内容導入資料庫–ASP.NET MVC
JQuery ajax 實作關閉彈窗,重新整理清單
ASP.NET MVC的 Action跳轉方法歸納部分
jQuery實作checkbox多選,單選與資料庫互動傳值,指派整理
C# String字元串方法的使用歸納(直覺,粗暴)