zachvaldez
asked on
How can I change the backcolor of cells of the row selected of a listview?
Is it possible to change the row cells backcolor for asp.net web app not windows based?
http://forums.asp.net/p/1550692/3801663.aspx
Sorry, hit enter too soon.
There's a javascript solution on that page. If that doesn't suit you for some reason, the gridview control has a native way of changing the selected row color.
There's a javascript solution on that page. If that doesn't suit you for some reason, the gridview control has a native way of changing the selected row color.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Im gertting server tag not well formed using this from the former link..
<tr id="Tr2" runat="server" style="background-color:<% #(Containe r.DisplayI ndex == ListView1.SelectedIndex) ? "blue" : "#FFFBD6" %>;color: #333333;">
<tr id="Tr2" runat="server" style="background-color:<%
You need to change the <% %> to what you want, like this:
<tr id="Tr2" runat="server" style="background-color:#FFFBD6;color: #333333;">
ASKER
This is exactly what I have..
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text='<%# Eval("keyID") %>'
CommandName="Edit" />
</td>
but is not working meaning changing the backcolor.
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text='<%# Eval("keyID") %>'
CommandName="Edit" />
</td>
but is not working meaning changing the backcolor.
Hi, if you could post me your entire working listview from <asp:Listview> to </asp:Listview> then I can insert a SelectedItemTemplate for you to get you going...
ASKER
thanks, check it out
<asp:ListView ID="ListView1" runat="server" DataKeyNames="pkeyID"
style="margin-left: 0px">
<LayoutTemplate>
<table cellpadding="1" border="1" runat="server" id="tblNames">
<tr id="Tr1" runat="server">
<th id="Th2" runat="server">
Last Name
</th>
<th id="Th3" runat="server">
First Name
</th>
<th id="Th4" runat="server">
1st Choice A
</th>
<th id="Th5" runat="server">
1st Choice B
</th>
<th id="Th6" runat="server">
1st Choice C
</th>
<th id="Th1" runat="server" style="background-color: #FFFFCC">
</th>
<th id="Th14" runat="server" style="background-color: #FFFFCC">
</th>
<th id="Th15" runat="server" style="background-color: #FFFFCC">
</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server" style="background-color:#F FFBD6;colo r: #333333;">
<td>
<asp:Label ID="LastNameLabel" runat="Server" CssClass="cap" Text='<%#Eval("LastName") %>' />
</td>
<td valign="top">
<asp:Label ID="FirstNameLabel" runat="Server" CssClass="cap" Text='<%#Eval("FirstName") %>' />
</td>
<td valign="top">
<asp:Label ID="lblfirstchoiceA" runat="Server" Text='<%#Eval("FirstChoice A") %>' />
</td>
<td valign="top">
<asp:Label ID="lblfirstchoiceB" runat="Server" Text='<%#Eval("FirstChoice B") %>' />
</td>
<td valign="top">
<asp:Label ID="lblfirstchoiceC" runat="Server" Text='<%#Eval("FirstChoice C") %>' />
</td>
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit" OnClientClick="scrollToPos ition()" CommandName="Edit" CausesValidation="false"/>
</td>
<td>
<asp:LinkButton ID="LinkButton2" runat="Server" Text="Update" OnClientClick="window.scro llBy(0, document.body.scrollHeight )" CommandName="Update" CausesValidation="false" />
</td>
<td>
<asp:LinkButton ID="LinkButton1" runat="Server" OnClientClick="return confirm('OK to Delete?')" Text="Delete" CommandName="Delete" CausesValidation="false"/>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</form>
can u suggest also how to make it nicer?
<asp:ListView ID="ListView1" runat="server" DataKeyNames="pkeyID"
style="margin-left: 0px">
<LayoutTemplate>
<table cellpadding="1" border="1" runat="server" id="tblNames">
<tr id="Tr1" runat="server">
<th id="Th2" runat="server">
Last Name
</th>
<th id="Th3" runat="server">
First Name
</th>
<th id="Th4" runat="server">
1st Choice A
</th>
<th id="Th5" runat="server">
1st Choice B
</th>
<th id="Th6" runat="server">
1st Choice C
</th>
<th id="Th1" runat="server" style="background-color: #FFFFCC">
</th>
<th id="Th14" runat="server" style="background-color: #FFFFCC">
</th>
<th id="Th15" runat="server" style="background-color: #FFFFCC">
</th>
</tr>
<tr runat="server" id="itemPlaceholder" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr id="Tr2" runat="server" style="background-color:#F
<td>
<asp:Label ID="LastNameLabel" runat="Server" CssClass="cap" Text='<%#Eval("LastName") %>' />
</td>
<td valign="top">
<asp:Label ID="FirstNameLabel" runat="Server" CssClass="cap" Text='<%#Eval("FirstName")
</td>
<td valign="top">
<asp:Label ID="lblfirstchoiceA" runat="Server" Text='<%#Eval("FirstChoice
</td>
<td valign="top">
<asp:Label ID="lblfirstchoiceB" runat="Server" Text='<%#Eval("FirstChoice
</td>
<td valign="top">
<asp:Label ID="lblfirstchoiceC" runat="Server" Text='<%#Eval("FirstChoice
</td>
<td>
<asp:LinkButton ID="EditButton" runat="Server" Text="Edit" OnClientClick="scrollToPos
</td>
<td>
<asp:LinkButton ID="LinkButton2" runat="Server" Text="Update" OnClientClick="window.scro
</td>
<td>
<asp:LinkButton ID="LinkButton1" runat="Server" OnClientClick="return confirm('OK to Delete?')" Text="Delete" CommandName="Delete" CausesValidation="false"/>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
</form>
can u suggest also how to make it nicer?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Btw for changing the colour in the above code, use the following line (within the SelectedItemTemplate):
<tr id="Tr2" runat="server" style="background-color:#0 000FF;colo r: #FFFFFF;">
<tr id="Tr2" runat="server" style="background-color:#0
ASKER
nothing change, the row color did not change.