asp.net中的重复器 [英] repeator in asp.net

查看:97
本文介绍了asp.net中的重复器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







使用转发器作为锚标签,每当我将数据绑定到转发器时,锚标签ID都相同因为我没有调用脚本如何解决这些问题

Hi,


Am using repetor for anchor tag,whenever i bind the data to the repeator the anchor tag id is same for all created anchor tags in repeator because of that i failed to call the script how to solve these issue

推荐答案

使用Eval附加唯一ID。



Append the unique Id using Eval.

<a id="a_<%# Random() %><%# DataBinder.Eval(Container,"itemindex") %>" />






Random()是代码中的一个函数,后面会返回一个随机数



Random()is a function in your code behind which returns a random number


转发器中的各个锚标签将被赋予唯一ID。看看这个:

aspx页面:

The individual anchor tags in the repeater will be given unique ids. check this out:
aspx page:
<head runat="server">
    <script>
        function myfunction(obj) {
            alert(obj.id);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <div style="font-weight: bold;">
                    Repeater Demo</div>
            </HeaderTemplate>
            <ItemTemplate>
                <div>
                    <a href='<%# Container.DataItem %>' runat="server" onclick="myfunction(this);" id="mylink">
                        <%# Container.DataItem %></a>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>



代码落后:


code behind:

protected void Page_Load(object sender, EventArgs e)
{
    List<string> myList = new List<string>();
    myList.Add("Link1");
    myList.Add("Link2");
    myList.Add("Link3");

    Repeater1.DataSource = myList;

    Repeater1.DataBind();
}


这篇关于asp.net中的重复器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆