I have a datalist with itemtemplate which contains: an anchor and an href tag . Everytime a user clicks the link I want to change the background color to green of the so that the whole cell looks selected. If another cell is selected then the previous background should clear up and the new cell should get the green color. Right now all the td's change to green for a second and then it cjanges to the original colors. The issue is that I cannot get unique id because of the DataList control. There is a unique table name and but all the td are identical. So there are 2 issues.
- To have the background color remain until the user clicks another cell
- Have a unique id to recognize which cell was selected by the click event.
How can I do that? Please help.
<asp:DataList ID="DL1" ItemStyle-Width="50%" runat="server" DataSourceID="ds1"
RepeatColumns="2" RepeatDirection="Vertical" RepeatLayout="Table">
<ItemTemplate>
<a onclick="testl('<%= DL1.ClientID %>')"
href='<%# "Color.aspx?id=" + Eval("id") %>'>
Click to change background
</a>
</ItemTemplate>
</datalist>
function test(id) {
$("#" + id + " td").css({ 'background-color': 'green' });
}