您的位置:首页 > 其它

使用Repeater绑定数据,及提取显示数据进行操作的一点小方法!(模板列)

2009-10-22 16:09 1006 查看
//前台代码:(绑定数据库字段)

<asp:Repeater ID="repeater1" runat="server" onitemcommand="repeater1_ItemCommand" >
<ItemTemplate>
<div class="j" style="width: 150px; text-align: center">
<asp:TextBox ID="txtType" Text='<%# Eval("Type") %>' Width="100" runat="server">
</asp:TextBox>
</div>
<div class="j" style="width: 150px; text-align: center">
名称:<asp:TextBox ID="txtName" Text='<%# Eval("Name") %>' Width="100" runat="server"></asp:TextBox>
</div>
<div class="j" style="width: 250px; text-align: center">
内容:<asp:TextBox ID="txtAbout" Text='<%# Eval("About") %>' Width="200" runat="server"></asp:TextBox>
</div>
<div class="j" style="width: 100px; text-align: center">
<asp:ImageButton ID="Delete" CommandName="del" ImageUrl="~/images/1.png"
runat="server" />
<asp:Label ID="id" Visible="false" runat="server" Text=' <%# Eval("ID")%>'>
</asp:Label>
</div>

</ItemTemplate>
</asp:Repeater>


//后台代码:得到repeater显示的数据(遍例)

for (int i = 0; i < repeater1.Items.count; i++)
{
TextBox txtType = (TextBox)this.RptCus.Items[i].FindControl("txtType");
string type = txtType.Text;
TextBox txtName = (TextBox)this.RptCus.Items[i].FindControl("txtName");
string name = txtName.Text;
TextBox txtAbout = (TextBox)this.RptCus.Items[i].FindControl("txtAbout");
string about = txtAbout.Text;
Label id= (Label)this.RptCus.Items[i].FindControl("id");
int id=int.Parse(id.Text);
}


后记:

string id= "";
for (int i = 0; i < this.Repeater1.Items.Count; i++)
{
Label lbid= (Label)this.Repeater1.Items[i].FindControl("lbid");
id= id.Text;
}

repeater控件中包含标签lbid(Label)等控件,可通过以上方法得到其实绑定的值!

CSDN论坛内容:

GridView,Repeater,DataList中查找控件要遍历一下才可以
GridView:
for(int i=0; i <GridView.Rows.Count;i++)
{
Label lbl = (Label)GridView.Rows[i].FindControl("Label");
}
Repeater:
for(int i=0; i < Repeater.Items.Count;i++)
{
Label lbl = (Label) Repeater.Items[i].FindControl("Label");
}
DataList:
for(int i=0; i < DataList.Items.Count;i++)
{
Label lbl = (Label) DataList.Items[i].FindControl("Label");
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐