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

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;
                //语句块
            }
        }
    }
}

 

 

 

posted @ 2013-05-30 10:28  沐雪架构师  阅读(450)  评论(0)    收藏  举报