我想动态填充一个列表并在我将鼠标悬停在按钮上时显示该列表
<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>
我的列表如下,我正在尝试动态构建它:
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";
}
编辑:
我已经成功地从代码隐藏中转移了列表,但是格式不正确想要显示图像一个在另一个下面
我的问题是如何将它传输到 aspx 设计页面?并显示在悬停事件上
请帮忙
最佳答案
将服务器端动态创建的ul
添加到Page
控件集合或页面的任意位置,并通过css或内联样式display使其默认隐藏:无
。为 ul
提供一个 id
或 class
,这将有助于在客户端找到该元素。
在客户端,您可以使用 $('ul.classname')
或 $('#listId)
找到它,然后使用 show( )
在悬停事件上并根据您的要求定位它。
基于您的代码。
给ul
一个id>
<ul ID="list" runat="server">
请注意,在 for
循环中,您应该将 anchor 添加到列表控件。
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
$('.invite-link').hover(function(){
$('#list').show();
}, function(){
$('#list').hide();
});
关于c# - 将列表从代码隐藏转移到 aspx 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9636315/