简体   繁体   English

将列表从代码背后转移到ASPX页面

[英]Transfer list from code behind to aspx page

I want to populate a List dynamically and display the list when i hover over a button 我想动态填充列表并在将鼠标悬停在按钮上时显示列表

<div class="invite">
    <asp:Button ID="Button1" runat="server" Text="Invite"  CssClass="invite-link"/>
    <div class="invite-drop">
        <div class="holder">
            <ul runat="server">
                <li>
                    <a href="#">
                        <img src="images/img3.png" width="22" height="22" alt="image description" />
                        <span>Chris Robin</span>
                    </a>
                </li>
                <li>
                    <a href="#">
                        <img src="images/img3.png" width="22" height="22" alt="image description" />
                        <span>Danny Defoee</span>
                    </a>
                </li>
                <li>
                    <a href="#">
                        <img src="images/img3.png" width="22" height="22" alt="image description" />
                        <span>Gustav Lee</span>
                    </a>
                </li>
                <li>
                    <a href="#">
                        <img src="images/img3.png" width="22" height="22" alt="image description" />
                        <span>Eric Rees</span>
                    </a>
                </li>
            </ul>
            <a class="select" href="#">Or select friend</a>
        </div>
    </div>
</div>

My list is as follows and i am trying to construct it dynamically : 我的清单如下,我正在尝试动态构建它:

HtmlGenericControl list = new HtmlGenericControl("ul");
for (int i = 0; i < 3; i++)
{
    HtmlGenericControl listItem = new HtmlGenericControl("li");
    HtmlGenericControl anchor = new HtmlGenericControl("a");
    Image im = new Image();
    //im.ImageUrl = ds.Tables[0].Rows[1].ItemArray.ToString();
    anchor.Attributes.Add("href", "");
    anchor.Controls.Add(im);
    anchor.InnerText = "TabX";
}

EDIT : 编辑:

在此处输入图片说明

i have been successful in transferring the list from codebehind however the formatting isnt correct want to display the images one below the other 我已经成功地从代码背后传输了列表,但是格式不正确,想要在另一个下面显示图像

My question is how do i transfer it to aspx design page? 我的问题是如何将其转移到aspx设计页面? and display it on the hover event 并将其显示在悬停事件上

Please help 请帮忙

Add the dynamically created ul from server side into Page controls collection or anywhere on the page and make it hidden by default through css or inline style display:none . 从服务器端将动态创建的ul添加到Page控件集合中或页面上的任何位置,并默认通过CSS或内联样式display:none将其隐藏。 Give an id or class to ul which will help to find the element on the client side. ul一个idclass ,这将有助于在客户端上查找元素。

On the client you can find it using $('ul.classname') or $('#listId) and then show it using show() on the hover event and position it as per your requirement. 在客户端上,您可以使用$('ul.classname')$('#listId)找到它,然后在悬停事件上使用show()显示它,并根据需要定位它。

Based on your code. 根据您的代码。

Give an id to ul ul一个ID

<ul ID="list" runat="server">

Note in the for loop you should add the anchor to the list control. 请注意,在for循环中,应将锚添加到列表控件中。

    for (int i = 0; i < 3; i++)
    {
        HtmlGenericControl listItem = new HtmlGenericControl("li");
        HtmlGenericControl anchor = new HtmlGenericControl("a");
        Image im = new Image();
        //im.ImageUrl = ds.Tables[0].Rows[1].ItemArray.ToString();
        anchor.Attributes.Add("href", "");
        anchor.Controls.Add(im);
        anchor.InnerText = "TabX";

        list.Controls.Add(anchor);
     }

Js s

$('.invite-link').hover(function(){
     $('#list').show();
}, function(){
     $('#list').hide();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM