I have a datalist that is populated using an ArrayList. When this is rendered i want to set the background image depending on a list item value, at the moment i have set the image in CSS but i dont know how i would change the image depending on the value.
Here is my code:
Page code:
<asp:DataList ID="dlTeam" runat="server" RepeatColumns="3" RepeatDirection="Horizontal">
<ItemTemplate>
<div class="teamPlayerStyle" playercode='<%# Eval("playerCode") %>'
position='<%# Eval("position") %>' team='<%# Eval ("team") %>'
playername='<%# Eval ("playerName") %>' value='<%# Eval ("playerValue") %>'
id='item_<%# Container.ItemIndex + 1 %>'>
<li>
<%# Eval("playerCode") %>
</li>
<li>
<%# Eval("position") %>
</li>
<li>
<%# Eval ("team") %>
</li>
<li>
<%# Eval ("playerName") %>
</li>
<li>
<%# Eval ("playerValue") %>
</li>
</div>
</ItemTemplate>
</asp:DataList>
The code behind is:
protected void Page_Load(object sender, EventArgs e)
{
BindData();
}
private void BindData()
{
object players = GetPlayers();
dlTeam.DataSource = players;
dlTeam.DataBind();
}
private object GetPlayers()
{
ArrayList playerList = new ArrayList();
PlayersDataSetTableAdapters.TeamsTableAdapter teamAdapter = new
PlayersDataSetTableAdapters.TeamsTableAdapter();
DataTable dt = new DataTable();
dt = teamAdapter.GetDataByTeamName("Team1");
foreach (DataRow dr in dt.Rows)
{
Player player = new Player();
player.playerCode = Convert.ToInt32(dr["Code"]);
player.playerName = dr["Name"].ToString();
player.position = dr["Position"].ToString();
player.team = dr["Team"].ToString();
player.playerValue = Convert.ToDecimal(dr["Value"]);
playerList.Add(player);
}
return playerList;
}
I have an image folder that contains an image for every team so for example, if the first datalist team node = "Liverpool" then the datalist item background should be set to Liverpool.gif and then the same for each team.
Any help is much appreciated.