formdatabind03.aspx
来自「asp做的新闻系统」· ASPX 代码 · 共 104 行
ASPX
104 行
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.Sql" %>
<html>
<script language="vb" runat=server>
Public CLASS book
private _name as string
private _price as decimal
public readonly property name as string
Get
return _name
end Get
end property
public readonly property price as decimal
Get
return _price
end Get
end Property
public sub New(n as string,p as decimal)
MyBase.New
_name=n
_price=p
end sub
End Class
Sub Page_Load(o as object,e as eventargs)
if IsPostBack
dim values as New ArrayList
values.add(New book("红楼梦",100.0))
values.add(New book("三国演义",90.0))
values.add(New book("水浒",85.0))
values.add(New book("西游记",60.0))
lbltxt.text="各种书的价格是:"
dg1.datasource=values
dg1.Databind
end if
End Sub
Public Function GetRealPrice(price as decimal)
dim a as decimal
a=CDbl(rate.selecteditem.value)
GetRealPrice=price*a
End Function
</script>
<head>
<title>
数据绑定试验
</title>
</head>
<body bgcolor=#ccccff>
<center>
<h2>数据绑定之表达式绑定</h2>
<hr>
<form runat=server>
请输入折扣率:
<asp:DropDownList id="rate" runat=server>
<asp:listitem>1.00</asp:listitem>
<asp:listitem>0.95</asp:listitem>
<asp:listitem>0.90</asp:listitem>
<asp:listitem>0.80</asp:listitem>
<asp:listitem>0.70</asp:listitem>
<asp:listitem>0.60</asp:listitem>
<asp:listitem>0.60</asp:listitem>
</asp:DropDownList>
<asp:button text="提交" runat=server/>
<hr>
<asp:label id="lbltxt" runat=server/>
<br>
<asp:datalist id="dg1" runat=server>
<template name="headertemplate">
<table>
<tr>
<th>
书名
</th>
<th>
价格
</th>
</tr>
</template>
<template name="itemtemplate">
<tr>
<td>
<%# databinder.eval(container.dataitem,"name") %>
</td>
<td>
$<%# GetRealPrice(databinder.eval(container.dataitem,"price")) %> 元
</td>
</tr>
</template>
<template name="footertemplate">
</table>
</template>
</asp:datalist>
</form>
</center>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?