zoukankan      html  css  js  c++  java
  • 如何在后台获得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;
                    //语句块
                }
            }
        }
    }

    作者:沐雪
    文章均系作者原创或翻译,如有错误不妥之处,欢迎各位批评指正。本文版权归作者和博客园共有,如需转载恳请注明。
    如果您觉得阅读这篇博客让你有所收获,请点击右下方【推荐】
    找一找教程网-随时随地学软件编程 http://www.zyiz.net/

  • 相关阅读:
    centOS7虚拟机连接大网
    [CSP-S模拟测试48]反思+题解
    [CSP-S模拟测试47]反思+题解
    [bzoj2456]mode 题解
    [CSP-S模拟测试45]题解
    [CSP模拟测试43、44]题解
    [CSP-S模拟测试41]题解
    [NOIP模拟测试38]题解
    一些idea
    [NOIP模拟测试37]反思+题解
  • 原文地址:https://www.cnblogs.com/puzi0315/p/3107628.html
Copyright © 2011-2022 走看看