DataList Close SelectedItem

Discussion in 'ASP .Net' started by rn5a@rediffmail.com, Sep 24, 2007.

  1. Guest

    An ASPX page has a DataList which only displays the first name of the
    users. When any of the first names is clicked, the DataList displays
    the details of that user i.e. his full name, e-mail, address etc. This
    is how I am doing it:

    <script runat="server">
    Sub Page_Load(.....)
    'populate the data source with
    'the data & bind it to the DataList
    End Sub

    Sub dl_ItemCommand(..........)
    dl.SelectedIndex = ea.Item.ItemIndex
    dl.DataBind()
    End Sub
    </script>

    <form runat="server">
    <asp:DataList ID="dl" OnItemCommand="dl_ItemCommand"
    RepeatLayout="table" RepeatDirection="horizontal" runat="server">
    <ItemTemplate>
    <asp:LinkButton ID="lnkFName" CommandName="Select" runat="server"><%#
    Container.DataItem("FirstName") %></asp:LinkButton> | &nbsp;
    </ItemTemplate>
    <SelectedItemTemplate>
    Name: <%# Container.DataItem("FirstName") & " " &
    Container.DataItem("LastName") %><br>
    E-Mail;<%# Container.DataItem("EMail") %><br>
    Address: <%# Container.DataItem("Address") %>&nbsp;
    <%# Container.DataItem("City") %>&nbsp;
    <%# Container.DataItem("State") %>&nbsp;
    <%# Container.DataItem("Zip") %><br><br>
    </SelectedItemTemplate>
    </asp:DataList>
    </form>

    The above code shows the details of the user when the first name of a
    user is clicked but I also want a LinkButton to accompany the details
    of each user which when clicked should hide the details & display just
    the first name of the user that was selected. There's no problem in
    adding a LinkButton with the details which I did by adding a
    LinkButton just before the </SelectedItemTemplate> line.

    <asp:LinkButton ID="lnkClose" CommandArgument='<%#
    Container.DataItem("FirstName") %>' Text="CLOSE" runat="server"/>

    So when the first name of a user is clicked, it gets replaced by the
    details of that user along with a "CLOSE" LinkButton. The problem is
    when the "CLOSE" LinkButton (which is displayed along with the details
    of the user) is clicked, how do I hide the details of the selected
    user (plus the "CLOSE" LinkButton) & display only the user's first
    name .

    I can't use the <EditItemTemplate> in this case since the CommandName
    of the LinkButton "lnkFName" has already been set to Select.
     
    , Sep 24, 2007
    #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. Scott Reynolds

    DataList Selecteditem template

    Scott Reynolds, Aug 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    3,355
    Scott Reynolds
    Aug 27, 2004
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,941
  3. Roger

    SelectedItem from DataList

    Roger, Jan 10, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    431
    Roger
    Jan 10, 2005
  4. sling blade
    Replies:
    3
    Views:
    2,727
    Burak SARICA
    Feb 28, 2005
  5. Iñaki Baz Castillo
    Replies:
    7
    Views:
    920
    Iñaki Baz Castillo
    Jan 12, 2010
Loading...

Share This Page