Link to home
Start Free TrialLog in
Avatar of zachvaldez
zachvaldezFlag for United States of America

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?
Avatar of Paul MacDonald
Paul MacDonald
Flag of United States of America image

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.
SOLUTION
Avatar of tlayton
tlayton
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zachvaldez

ASKER

Im gertting server tag not well formed using this from the former link..

<tr id="Tr2" runat="server"  style="background-color:<%#(Container.DisplayIndex == ListView1.SelectedIndex) ? "blue" : "#FFFBD6" %>;color: #333333;">
You need to change the <% %> to what you want, like this:
<tr id="Tr2" runat="server" style="background-color:#FFFBD6;color: #333333;">

Open in new window

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.
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...
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:#FFFBD6;color: #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("FirstChoiceA") %>' />
                    </td>
                    <td valign="top">
                        <asp:Label ID="lblfirstchoiceB" runat="Server" Text='<%#Eval("FirstChoiceB") %>' />
                    </td>
                    <td valign="top">
                        <asp:Label ID="lblfirstchoiceC" runat="Server" Text='<%#Eval("FirstChoiceC") %>' />
                    </td>
 
           
                   
                    <td>
                     <asp:LinkButton ID="EditButton" runat="Server" Text="Edit" OnClientClick="scrollToPosition()"  CommandName="Edit" CausesValidation="false"/>
                       
                    </td>
                    <td>
                        <asp:LinkButton ID="LinkButton2" runat="Server" Text="Update" OnClientClick="window.scrollBy(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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Btw for changing the colour in the above code, use the following line (within the SelectedItemTemplate):

<tr id="Tr2" runat="server" style="background-color:#0000FF;color: #FFFFFF;">
nothing change, the row color did not change.