ListView Selected Item Not Working

Discussion in 'ASP .Net' started by Mike Collins, Aug 12, 2008.

  1. Mike Collins

    Mike Collins Guest

    I have a listview that when I select an item, it populates a details view. I
    want to show the item that was selected in the listview by changing it to
    yellow. Trouble is, the selected item does not show as yellow until I've
    clicked the same item two times. What am I doing wrong on the selected item
    that keeps it from changing to yellow until the item is clicked two times?
    Also, I have to set the listviews selectedIndex in the SelectedIndexChanging
    event. Not sure if this is related to the color problem, but is that what you
    are supposed to do?

    <asp:ListView ID="lvSearchResults" DataKeyNames="MemberID"
    OnDataBound="lvSearchResults_DataBound"
    OnSelectedIndexChanging="lvSearchResults_SelectedIndexChanging"
    OnSelectedIndexChanged="lvSearchResults_SelectedIndexChanged" runat="server">
    <ItemTemplate>
    <div id="Div1" style="text-align: left; border: solid 1px gray;
    background-color: #F7F6F3; color: #333333; position: relative;"
    runat="server">
    <h5 style="display: inline;">
    Member ID:
    </h5>
    <asp:Label ID="MemberIDLabel" runat="server" Text='<%# Eval("MemberID")
    %>' />
    <br />
    <h5 style="display: inline;">
    Name:
    </h5>
    <asp:Label ID="FullnameLabel" runat="server" Text='<%# Eval("FullName")
    %>' />
    <br />
    <h5 style="display: inline;">
    State/Postal Code:
    </h5>
    <asp:Label ID="StateCodeLabel" runat="server" Text='<%# Eval("State") %>'
    />
    /
    <asp:Label ID="PostalCodeLabel" runat="server" Text='<%#
    Eval("PostalCode") %>' />
    <br />
    <h5 style="display: inline;">
    Home Phone:
    </h5>
    <asp:Label ID="HomePhoneNumberLabel" runat="server" Text='<%#
    Eval("PhoneNumber") %>' />
    <br />
    <asp:CheckBox ID="ActionFlagCheckBox" runat="server" Checked='<%#
    Eval("ActionFlag") %>'
    Enabled="false" Style="font-weight: bold;" Text="Action Flag" />
    <asp:ImageButton ID="btnSelect" Style="position: absolute; bottom: 2px;
    right: 2px;" CommandName="Select" ImageUrl="~/Images/Buttons/s_select_0.png"
    tooltip="Submit this search criteria" runat="server" />
    </div>
    </ItemTemplate>
    <AlternatingItemTemplate>
    <div id="Div2" style="text-align: left; border: solid 1px gray;
    background-color: #FFFFFF; color: #333333; position: relative;"
    runat="server">
    <h5 style="display: inline;">
    Member ID:
    </h5>
    <asp:Label ID="MemberIDLabel" runat="server" Text='<%# Eval("MemberID")
    %>' />
    <br />
    <h5 style="display: inline;">
    Name:
    </h5>
    <asp:Label ID="FullnameLabel" runat="server" Text='<%# Eval("Fullname")
    %>' />
    <br />
    <h5 style="display: inline;">
    State/Postal Code:
    </h5>
    <asp:Label ID="StateCodeLabel" runat="server" Text='<%# Eval("State") %>'
    />
    /
    <asp:Label ID="PostalCodeLabel" runat="server" Text='<%#
    Eval("PostalCode") %>' />
    <br />
    <h5 style="display: inline;">
    Home Phone:
    </h5>
    <asp:Label ID="HomePhoneNumberLabel" runat="server" Text='<%#
    Eval("PhoneNumber") %>' />
    <br />
    <asp:CheckBox ID="ActionFlagCheckBox" runat="server" Checked='<%#
    Eval("ActionFlag") %>'
    Enabled="false" Style="font-weight: bold;" Text="Action Flag" />
    <asp:ImageButton ID="btnSelect" Style="position: absolute; bottom: 2px;
    right: 2px;" CommandName="Select" ImageUrl="~/Images/Buttons/s_select_0.png"
    tooltip="Submit this search criteria" runat="server" />
    </div>
    </AlternatingItemTemplate>
    <LayoutTemplate>
    <div id="itemPlaceholder" style="text-align: center; background-color:
    #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
    color: #000000;" runat="server">
    </div>
    </LayoutTemplate>
    <SelectedItemTemplate>
    <div id="Div3" style="text-align: left; border: solid 1px gray;
    background-color: #FFFF99; color: #333333;" runat="server">
    Member ID:
    <asp:Label ID="MemberIDLabel" runat="server" Text='<%# Eval("MemberID")
    %>' />
    <br />
    Name:
    <asp:Label ID="FullnameLabel" runat="server" Text='<%# Eval("Fullname")
    %>' />
    <br />
    State/Postal Code:
    <asp:Label ID="StateCodeLabel" runat="server" Text='<%# Eval("State") %>'
    />
    /
    <asp:Label ID="PostalCodeLabel" runat="server" Text='<%#
    Eval("PostalCode") %>' />
    <br />
    Home Phone:
    <asp:Label ID="HomePhoneNumberLabel" runat="server" Text='<%#
    Eval("PhoneNumber") %>' />
    <br />
    <asp:CheckBox ID="ActionFlagCheckBox" runat="server" Checked='<%#
    Eval("ActionFlag") %>'
    Enabled="false" Text="Action Flag" />
    <br />
    </div>
    </SelectedItemTemplate>
    <ItemSeparatorTemplate>
    <br />
    </ItemSeparatorTemplate>
    </asp:ListView>


    protected void lvSearchResults_SelectedIndexChanging(object sender,
    ListViewSelectEventArgs e)
    {
    lvSearchResults.SelectedIndex = e.NewSelectedIndex;
    }

    <asp:ObjectDataSource ID="odsQuickDetails" runat="server"
    OldValuesParameterFormatString="original_{0}"
    SelectMethod="GetQuickDetails" TypeName="App_Classes.Members">
    <SelectParameters>
    <asp:ControlParameter ControlID="lvSearchResults" Name="MemberID"
    PropertyName="SelectedValue" Type="String" />
    </SelectParameters>
    </asp:ObjectDataSource>
     
    Mike Collins, Aug 12, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Iain
    Replies:
    3
    Views:
    959
  2. shapper
    Replies:
    1
    Views:
    493
    shapper
    Feb 19, 2008
  3. WebBuilder451

    ListView selected index

    WebBuilder451, Apr 25, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    3,472
    WebBuilder451
    Apr 25, 2008
  4. .
    Replies:
    0
    Views:
    773
  5. mldardy
    Replies:
    0
    Views:
    992
    mldardy
    Sep 28, 2010
Loading...

Share This Page