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/

  • 相关阅读:
    c++多继承布局
    copy constructor
    default construction
    对象模型如何影响程序
    c++对象模型-对象模型
    在网站中引入特殊字体
    数组基础相关
    CSS3 transform3D
    即时效果--元素出现在页面特定区域时加载
    svg动态绘制饼状图
  • 原文地址:https://www.cnblogs.com/puzi0315/p/3107628.html
Copyright © 2011-2022 走看看