Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6089995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:09:48+00:00 2026-05-23T12:09:48+00:00

I have a following problem. I have a ListView which returns data from SQL

  • 0

I have a following problem. I have a ListView which returns data from SQL table. One of its columns looks like “Ambient/Trance/Goa Trance/House”.

All i want to do is parse this column and create buttons for each value, for example a button for “Ambient”, a button for “Trance”, etc.

I tried to create buttons in ItemDataBound event in the following way:

    Dim ListView_Albums_PlaceHolder_Artists As PlaceHolder = e.Item.FindControl("ListView_Albums_PlaceHolder_Artists")

    Dim Artists As String() = e.Item.DataItem("album_artists").ToString.Split("/")
    Dim ArtistsN As String() = e.Item.DataItem("album_artists_n").ToString.Split("/")

    Dim ListView_Albums_Literal_Artists As New Literal

    If Artists.Length = 1 Then
        ListView_Albums_Literal_Artists.Text = "Artist: "
    Else
        ListView_Albums_Literal_Artists.Text = "Artists: "
    End If

    ListView_Albums_PlaceHolder_Artists.Controls.Add(ListView_Albums_Literal_Artists)

    For Integer1 As Integer = 0 To Artists.Length - 1
        Dim ListView_Albums_LinkButton_Artist As New LinkButton
        ListView_Albums_LinkButton_Artist.Text = ArtistsN(Integer1)
        ListView_Albums_LinkButton_Artist.CommandName = "Artist"
        ListView_Albums_LinkButton_Artist.CommandArgument = Artists(Integer1)
        ListView_Albums_LinkButton_Artist.CssClass = "a-03"

        ListView_Albums_PlaceHolder_Artists.Controls.Add(ListView_Albums_LinkButton_Artist)

        Dim ListView_Albums_Literal As New Literal
        ListView_Albums_Literal.Text = ", "

        If Not Integer1 = Artists.Length - 1 Then
            ListView_Albums_PlaceHolder_Artists.Controls.Add(ListView_Albums_Literal)
        End If
    Next

They created fine but they didn’t work at all. I tried to Add Handler for Click or Command event but it also didn’t help.

Please help me to solve my problem!

Edit:

As VinayC suggested I changed ItemDataBound to ItemCreated. That helped, but I faced another problem: as far as I understand e.Item.DataItem or, maybe, e.Item becomes Nothing on PostBacks so the buttons do not work.

How to solve that problem? Thanks once again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T12:09:48+00:00Added an answer on May 23, 2026 at 12:09 pm

    So, I solved my problem. The solution wasn’t simple but here it is:

    In ItemCreated event I firstly count the number of buttons, then save it to ViewState, and only then I create buttons. I had to save the number of buttons to ViewState because on every postback e.Item.DataItem becomes Nothing.

    Maybe there is a simplier solution but I found only that one…

    Sub OnItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs)
        Dim ListView_Albums_PlaceHolder_Artists As PlaceHolder = e.Item.FindControl("ListView_Albums_PlaceHolder_Artists")
    
        If Not ListView_Albums_PlaceHolder_Artists Is Nothing Then
            If Not e.Item.DataItem Is Nothing Then
                ViewState("Length") = e.Item.DataItem("album_artists").ToString.Split("/").Length
            End If
    
            If Not ViewState("Length") Is Nothing Then
                Dim Length As Integer = ViewState("Length")
    
                For Integer1 As Integer = 0 To Length - 1
                    Dim ListView_Albums_LinkButton_Artist As New LinkButton
                    ListView_Albums_LinkButton_Artist.ID = "ListView_Albums_LinkButton_Artist_" & Integer1
    
                    ListView_Albums_PlaceHolder_Artists.Controls.Add(ListView_Albums_LinkButton_Artist)
                Next
            End If
        End If
    End Sub
    
    Sub OnItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewItemEventArgs)
        Dim ListView_Albums_PlaceHolder_Artists As PlaceHolder = e.Item.FindControl("ListView_Albums_PlaceHolder_Artists")
    
        If Not ListView_Albums_PlaceHolder_Artists Is Nothing Then
            If Not e.Item.DataItem Is Nothing Then
                Dim Artists As String() = e.Item.DataItem("album_artists").ToString.Split("/")
                Dim Artists_N As String() = e.Item.DataItem("album_artists_n").ToString.Split("/")
    
                For Integer1 As Integer = 0 To Artists.Length - 1
                    Dim ListView_Albums_LinkButton_Artist As LinkButton = e.Item.FindControl("ListView_Albums_LinkButton_Artist_" & Integer1)
    
                    ListView_Albums_LinkButton_Artist.CommandArgument = Artists(Integer1)
                    ListView_Albums_LinkButton_Artist.Text = Artists_N(Integer1)
                    ListView_Albums_LinkButton_Artist.CssClass = "a-03"
                Next
            End If
        End If
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem in my Data Structures and Problem Solving using Java
I have the following problem. If I query values with a keyfigure which is
I'm new to android and I have following problem I have a ListView. The
I have the following problem: I have an HTML textbox ( <input type=text> )
I have the following problem using subversion: I'm currently working on the trunk of
I have the following problem using template instantiation [*]. file foo.h class Foo {
I have the following problem: I open the dialog, open the SIP keyboard to
Avast there fellow programmers! I have the following problem: I have two rectangles overlapping
I have got the following problem since the server has safe mode turned on,
Has anyone encountered the following problem: I have IIS7 running on my computer. On

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.