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. List view and SelectedItemTemplate problem "Help"

List view and SelectedItemTemplate problem "Help"

Scheduled Pinned Locked Moved ASP.NET
helpquestioncsharp
3 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.
  • O Offline
    O Offline
    orsini
    wrote on last edited by
    #1

    Hi, I am new to .net and i have this maybe silly question. i have this test list view and i want to take a item field and poste it in a label when selected. here is the code. Protected Sub DepartmentsListView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) MessageLabel.Text = "The key value is " & _ DepartmentsListView.SelectedValue.ToString() & "." Label1.Text = DepartmentsListView.SelectedItemTemplate.InstantiateIn(what else come here?) End Sub I was looking for info on that, but not luck. thanks for you attention

    A 1 Reply Last reply
    0
    • O orsini

      Hi, I am new to .net and i have this maybe silly question. i have this test list view and i want to take a item field and poste it in a label when selected. here is the code. Protected Sub DepartmentsListView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) MessageLabel.Text = "The key value is " & _ DepartmentsListView.SelectedValue.ToString() & "." Label1.Text = DepartmentsListView.SelectedItemTemplate.InstantiateIn(what else come here?) End Sub I was looking for info on that, but not luck. thanks for you attention

      A Offline
      A Offline
      Andreas X
      wrote on last edited by
      #2

      Hello! The selectedItemTemplate is only a template of how the item should be displayed. You should write something like this instead: You have to excuse my lack of VB knowledge

      Protected Sub DepartmentsListView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

      MessageLabel.Text = "The key value is " & _
      DepartmentsListView.SelectedValue.ToString() & "."

      Here comes my non VB skills in hand :)

      ListViewDataItem dataItem = DepartmentsListView.Items[DepartmentsListView.SelectedIndex]

      Label1.Text = dataItem.FindControl("TheItemField").Text

      End Sub

      And as i said, i have never written VB so the syntax may be totaly wrong, but hopefuly if will guide you some. and also, i have not tested the code.

      Andreas Johansson
      IT Professional at Office IT Partner i Norrbotten Sweden
      What we don't know. We learn.
      What you don't know. We teach

      O 1 Reply Last reply
      0
      • A Andreas X

        Hello! The selectedItemTemplate is only a template of how the item should be displayed. You should write something like this instead: You have to excuse my lack of VB knowledge

        Protected Sub DepartmentsListView_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

        MessageLabel.Text = "The key value is " & _
        DepartmentsListView.SelectedValue.ToString() & "."

        Here comes my non VB skills in hand :)

        ListViewDataItem dataItem = DepartmentsListView.Items[DepartmentsListView.SelectedIndex]

        Label1.Text = dataItem.FindControl("TheItemField").Text

        End Sub

        And as i said, i have never written VB so the syntax may be totaly wrong, but hopefuly if will guide you some. and also, i have not tested the code.

        Andreas Johansson
        IT Professional at Office IT Partner i Norrbotten Sweden
        What we don't know. We learn.
        What you don't know. We teach

        O Offline
        O Offline
        orsini
        wrote on last edited by
        #3

        thank so much for you help. it is very close to that, do you know how is it in C# then, i can convert it. I try it the way you did, and still something missing there.

        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