repeater获取控件对象与数据绑定
repeater 控件用于显示重复的项目列表,这些项目被限制在该控件。
实例
repeater 控件
带有 <alternatingitemtemplate> 的 repeater 控件
带有 <separatortemplate> repeater 控件
得到id
for (int i = 0; i < repwarehouselist.items.count; i++)
{
text += repwarehouselist.items[i].controls[1].clientid+",";}
第二步:获取了id,在用findcontrol("txt")这个获取
//textbox tb = repwarehouselist.findcontrol(test) as textbox;
数据绑定实例
<%@ page language=vb debug=true %>
<%@ import namespace="system.data" %>
<script runat=server>
private mydt as new datatable
sub page_load(byval sender as object, byval e as eventargs)
dim myrow as datarow
mydt.columns.add(new datacolumn("employeeid", _
gettype(int32)))
mydt.columns.add(new datacolumn("employeefirstname", _
gettype(string)))
mydt.columns.add(new datacolumn("employeelastname", _
gettype(string)))
mydt.columns.add(new datacolumn("birthdate", _
gettype(date)))
mydt.columns.add(new datacolumn("salary", _
gettype(single)))myrow = mydt.newrow()
myrow(0) = 1
myrow(1) = "bob"
myrow(2) = "miller"
myrow(3) = "5/15/65"
myrow(4) = "40000"
mydt.rows.add(myrow)
myrow = mydt.newrow()
myrow(0) = 2
myrow(1) = "jenny"
myrow(2) = "fry"
myrow(3) = "7/22/75"
myrow(4) = "73050"
mydt.rows.add(myrow)
myrow = mydt.newrow()
myrow(0) = 3
myrow(1) = "lisa"
myrow(2) = "smith"
myrow(3) = "12/8/71"
myrow(4) = "62500"
mydt.rows.add(myrow)
myrow = mydt.newrow()
myrow(0) = 4
myrow(1) = "stephanie"
myrow(2) = "myer"
myrow(3) = "3/15/54"
myrow(4) = "43222"
mydt.rows.add(myrow)
myrow = mydt.newrow()
myrow(0) = 5
myrow(1) = "jimmy"
myrow(2) = "parker"
myrow(3) = "3/12/47"
myrow(4) = "52825"
mydt.rows.add(myrow)rpt1.datasource = mydt
rpt1.databind()
end sub
</script>
<html>
<head>
<title>repeater control sample page</title>
</head>
<body >
<form runat="server">
<font face="tahoma">
<asp教程:repeater
id="rpt1"
runat="server"
>
<headertemplate>
<table width="100%" style="font: 8pt verdana">
<tr style="background-color:dfecd8">
<td><b>employee id</b></td>
<td><b>first name</b></td>
<td><b>last name</b></td>
<td><b>birth date</b></td>
<td><b>salary</b></td>
</tr>
</headertemplate>
<itemtemplate>
<tr style="background-color:ffecd9">
<td>
<%# databinder.eval(container.dataitem, "employeeid") %>
</td>
<td>
<%# databinder.eval(container.dataitem, "employeefirstname") %>
</td>
<td>
<%# databinder.eval(container.dataitem, "employeelastname") %>
</td>
<td>
<%# format(databinder.eval(container.dataitem, "birthdate"), "short date") %>
</td>
<td>
<%# formatcurrency(databinder.eval(container.dataitem, "salary")) %>
</td>
</tr>
</itemtemplate>
<alternatingitemtemplate>
<tr style="background-color:ffeca8">
<td>
<%# databinder.eval(container.dataitem, "employeeid") %>
</td>
<td>
<%# databinder.eval(container.dataitem, "employeefirstname") %>
</td>
<td>
<%# databinder.eval(container.dataitem, "employeelastname") %>
</td>
<td>
<%# format(databinder.eval(container.dataitem, "birthdate"), "short date") %>
</td>
<td>
<%# formatcurrency(databinder.eval(container.dataitem, "salary")) %>
</td>
</tr>
</alternatingitemtemplate>
<separatortemplate>
<tr style="background-color:white">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</separatortemplate>
<footertemplate>
<tr style="background-color:dfecd8">
<td><b>employee id</b></td>
<td><b>first name</b></td>
<td><b>last name</b></td>
<td><b>birth date</b></td>
<td><b>salary</b></td>
</tr>
</table>
</footertemplate>
</asp:repeater></font>
</form>
</body>
</html>
在flash中获取项目位置
<?xml version="1.0"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:script>
[bindable]
public var myarray:array=[10,20,30,40];
</mx:script>
<mx:arraycollection id="myac" source="{myarray}"/>
<mx:repeater id="myrep" dataprovider="{myac}">
<mx:label id="label1" text="this is loop #{myrep.currentindex+1}"/>
</mx:repeater>
</mx:application>