您的位置:首页 > Web前端 > HTML

如何在后台获得Repeate项里的Html标签

2013-05-30 10:28 218 查看
HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="rptDemo" runat="server">
<ItemTemplate>
<div>
<input type="checkbox" runat="server" id="ckItem" /><div id="div" runat="server">
<%# Eval("Name") %>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
<asp:Button ID="btn" runat="server" Text="Click" onclick="btn_Click"
style="height: 21px" />
</body>
</html>


C#:

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void btn_Click(object sender, EventArgs e)
{
for (int i = 0; i < this.rptDemo.Items.Count; i++)
{
System.Web.UI.HtmlControls.HtmlInputCheckBox htmlCkBox = this.rptDemo.Items[i].FindControl("ckItem") as System.Web.UI.HtmlControls.HtmlInputCheckBox;
if (htmlCkBox != null)
{
//语句块
}
System.Web.UI.HtmlControls.HtmlContainerControl hcc = this.rptDemo.Items[i].FindControl("div") as System.Web.UI.HtmlControls.HtmlContainerControl;
if (hcc != null)
{
string temp = hcc.InnerHtml;
//语句块
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: