开发者

Adding an image to the first item in a listview?

开发者 https://www.devze.com 2023-04-12 12:17 出处:网络
I have created a listview which pulls the scores of users held in a database. For the p开发者_开发技巧erson who is number one I would like to add a small image of a star but I am confused as to how I

I have created a listview which pulls the scores of users held in a database.

For the p开发者_开发技巧erson 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


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 the ListViewItem 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号