将图像添加到列表视图中的第一项?
我创建了一个列表视图,它可以提取数据库中保存的用户分数。
对于排名第一的人,我想添加一个星星的小图像,但我很困惑我将如何去做?
到目前为止,我的代码如下,
var data = from x in db.DT_BenchScores
where x.Enabled == true
orderby x.Max_Bench descending, x.Date descending
select new
{
x.ScoreID,
x.Alias,
Bench = x.Max_Bench + "kg",
};
LV_Scores.DataSource = data.Take(20);
LV_Scores.DataBind();
我想在第一个人旁边添加以下内容
<span class="fr"><img src="_includes/images/no1.jpg" /></span>
有人可以解释一下我将如何做到这一点吗???
非常感谢
I have created a listview which pulls the scores of users held in a database.
For the person who is number one I would like to add a small image of a star but I am confused as to how I would go about this???
so far my code is as follows
var data = from x in db.DT_BenchScores
where x.Enabled == true
orderby x.Max_Bench descending, x.Date descending
select new
{
x.ScoreID,
x.Alias,
Bench = x.Max_Bench + "kg",
};
LV_Scores.DataSource = data.Take(20);
LV_Scores.DataBind();
I would like to add the following next to the first person
<span class="fr"><img src="_includes/images/no1.jpg" /></span>
Can someone please explain how I would do this???
Many Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
ItemDataBound
事件 (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemdatabound.aspx) 来响应每个项目从数据库行绑定的时间。在此事件处理程序中,您可以访问正在创建的ListViewItem
,并根据需要对其进行修改。编辑
请参阅此 CodeProject 帖子以获取示例:http ://www.codeproject.com/KB/webforms/ItemCreated.aspx?msg=1540986
You can use the
ItemDataBound
event (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemdatabound.aspx) to respond each time an item is bound from a database row. In this event handler, you can access theListViewItem
that is being created, and modify it as needed.EDIT
See this CodeProject post for a sample: http://www.codeproject.com/KB/webforms/ItemCreated.aspx?msg=1540986