zoukankan      html  css  js  c++  java
  • ASP.NET repeater添加序号列的方法及根据条件添加html(转)

    ASP.NET repeater添加序号列的方法

    1、<itemtemplate>
    <tr><td>
    <%# Container.ItemIndex + 1%>
    </td></tr>
    </itemtemplate>

    2、<itemtemplate>
    <tr><td>
    <%# this.rpResult.Items.Count + 1%>
    </td></tr>
    </itemtemplate>

    3、

    在<form></form>中添加<Label ID="dd" ></Label>

    <body nload="show()">

    <Script. Language="JScript">
    function show()
    {
    var bj = document.all.tags("LABEL");
    for (i=0;i<obj.length;i++)
    {
    document.all["dd"][i].innerHTML=i+1;
    }
    }
    </script>

    4、

    后台实现方法:

    在.aspx里添加<asp:Label id="Label1" Runat="server"></asp:Label>

    在.cs里添加

    ** void InitializeComponent()
    {
    this.Repeater1.ItemDataBound += new System.Web.UI.WebControls.RepeaterItemEventHandler(this.Repeater1_ItemDataBound);
    this.Load += new System.EventHandler(this.Page_Load);

    }

    ** void Repeater1_ItemDataBound(object source, System.Web.UI.WebControls.RepeaterItemEventArgs e)
    {
    if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    ((Label)e.Item.FindControl("Label1")).Text = Convert.ToString(e.Item.ItemIndex + 1);
    }
    }

    根据条件添加html

      <%#Container.ItemIndex == 8 ? "<br><a href = 'http://www.ginchan.com.tw/' target='_blank'><img style='338px;heigh:70px' src='/ImportAD/ADmid.gif'> </a>" : ""%>

    asp.net Repeater中以条件判断进行显示的方法

    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    try
    {
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
    String DRV = ((DataRowView)(e.Item.DataItem)).Row["state"].ToString();//得到要做为条件的某一项的值
    if (DRV == "停止")
    {
    ((LinkButton)e.Item.Controls[e.Item.Controls.Count - 2].FindControl("DeleteLinkButton")).Text = "";
    }
    }
    }
    catch
    {

    }
    }
    protected void Repeater1_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
    try
    {
    if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
    {
    String DRV = ((DataRowView)(e.Item.DataItem)).Row["state"].ToString();
    if (DRV == "停止")
    {
    ((LinkButton)e.Item.Controls[e.Item.Controls.Count - 2].FindControl("DeleteLinkButton")).Text = "";
    }
    }
    }
    catch
    {

    }
    }

  • 相关阅读:
    C# 数据为空,不能对NULL调用此方法或属性的解决办法
    Hadoop开启后jps显示只有jps
    Ubuntu中eclipse端口被占
    Ubuntu在终端执行命令时出现的错误
    sudo passwd root输入普通用户密码后显示用户不再sudoers文件中
    周总结(4.4)
    《构建之法》读后感(三)
    周总结(3.28)
    软件工程团队项目介绍
    解决phpstudy中nginx服务器运行项目报错404问题
  • 原文地址:https://www.cnblogs.com/dwfbenben/p/2783393.html
Copyright © 2011-2022 走看看