Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. datlist, select item

datlist, select item

Scheduled Pinned Locked Moved ASP.NET
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chrissy Callen
    wrote on last edited by
    #1

    ive never used datalists before and i'd really appreciate some help? What i'd like to do is select an item (eg, hyperlink or button) from a datalist on one webform, which will either: a) transfer to another datalist on another webform, showing more details of that particular record ... or b) open up the details of that record directly underneath. Ive no idea where to start and the more i look it up the more i get confused Chrissy Callen

    M 1 Reply Last reply
    0
    • C Chrissy Callen

      ive never used datalists before and i'd really appreciate some help? What i'd like to do is select an item (eg, hyperlink or button) from a datalist on one webform, which will either: a) transfer to another datalist on another webform, showing more details of that particular record ... or b) open up the details of that record directly underneath. Ive no idea where to start and the more i look it up the more i get confused Chrissy Callen

      M Offline
      M Offline
      Mike Ellison
      wrote on last edited by
      #2

      Hi there Chrissy. As a starting point, you may want to look at the ASP.NET QuickStart Tutorials[^] - the tutorial Introducing Web Forms gives some good examples of working with a Datalist. I think you'd find the other tutorials helpful too, particularly those on data access and databinding. Here's one approach you could take to have a hyperlink in your datalist open a detail record on the same page. The DataList control has an ItemCommand event that can be triggered when a button/linkButton in the list is clicked. The button/linkButton can specify a CommandName and CommandArgument with details that are passed along with the event. So here's an example of a DataList that is assigned the procedure myDataList_ItemCommand for its ItemCommand event, with a LinkButton whose CommandName is set to "DetailsLink" (whatever makes sense for us) and CommandArgument is bound to the value from the database field [Sample1]. The template is also showing the value from field [Sample2].

      <asp:DataList id="myDataList" runat="server" RepeatColumns="2"
      GridLines="Both"
      OnItemCommand="myDataList_ItemCommand" >
      <ItemTemplate>
      <asp:LinkButton id="lbDetails" runat="server"
      Text='<%# DataBinder.Eval(Container.DataItem, "Sample1") %>'
      CommandName="DetailsLink"
      CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Sample1") %>' />
      <br />
      <%# DataBinder.Eval(Container.DataItem, "Sample2") %>
      </ItemTemplate>
      </asp:DataList>

      The event handler myDataList_ItemCommand can then inspect the CommandArgument value to find the id of the detail record that needs to be displayed, and call an procedure to do so:

      void myDataList_ItemCommand(object o, DataListCommandEventArgs e)
      {
      // is the command a click in our details link button?
      if (e.CommandName == "DetailsLink")
      {
      //if so, let's run a query to get the details
      DisplayDetailRecord(e.CommandArgument.ToString());
      }
      }

      The detail record could be displayed using a Panel whose Visible property is set to true by our custom DisplayDetailRecord procedure. So here's a full example page in C#. It assumes the sourc

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups