locked
Convert SelectList object to VB RRS feed

  • Question

  • User-2089506584 posted

    Hi,

    How can I convert this C# SelectList object to vb?

    List<Information> infoData = new List<Information> {
    new Information { infoID = 7, infoName = "Beer" },
    new Information { infoID = 3, infoName = "Whiskey" },
    new Information { infoID = 5, infoName = "Champagne" },
    };

    Wednesday, September 2, 2009 10:49 AM

Answers

  • User-227801874 posted

    Public Class Information
        Public _infoID As Integer = 1
        Public _infoName As String
        Public Sub New(ByVal infoID As Integer, ByVal infoName As String)
            _infoID = infoID
            _infoName = infoName
        End Sub
    End Class
    Partial Public Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim infoData As List(Of Information) = New List(Of Information)
            infoData.Add(New Information(7, "Beer"))
            infoData.Add(New Information(3, "Whiskey"))
            infoData.Add(New Information(5, "Champagne"))
            TextBox1.Text = infoData.Item(0)._infoID.ToString() & " " & infoData.Item(0)._infoName.ToString()
            TextBox2.Text = infoData.Item(1)._infoID.ToString() & " " & infoData.Item(1)._infoName.ToString()
            TextBox3.Text = infoData.Item(2)._infoID.ToString() & " " & infoData.Item(2)._infoName.ToString()
        End Sub
    End Class 

    Yes i know but i thought you might have Information Class. see this example............

    Hope this helps............

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 3, 2009 9:35 AM

All replies

  • User-227801874 posted

    Try this one

    Dim infoData As List(Of Information) = New List(Of Information)
    infoData.Add(New Information(infoID = 7, infoName = "Beer"))
    infoData.Add(New Information(infoID = 3, infoName = "Whiskey"))
    infoData.Add(New Information(infoID = 5, infoName = "Champagne"))

    hope it helps.............

    Wednesday, September 2, 2009 11:29 AM
  • User-2089506584 posted


    infoData.Add(New Information(infoID = 7, infoName = "Beer"))

    I got this error "Too many arguments to 'Public Sub New()'." [:(]

    infoData.Add(New Information(infoID = 7, infoName = "Beer"))

    Wednesday, September 2, 2009 9:40 PM
  • User-227801874 posted

    Public Class Information
        Public _infoID As Integer = 1
        Public _infoName As String
        Public Sub New(ByVal infoID As Integer, ByVal infoName As String)
            _infoID = infoID
            _infoName = infoName
        End Sub
    End Class
    Partial Public Class _Default
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim infoData As List(Of Information) = New List(Of Information)
            infoData.Add(New Information(7, "Beer"))
            infoData.Add(New Information(3, "Whiskey"))
            infoData.Add(New Information(5, "Champagne"))
            TextBox1.Text = infoData.Item(0)._infoID.ToString() & " " & infoData.Item(0)._infoName.ToString()
            TextBox2.Text = infoData.Item(1)._infoID.ToString() & " " & infoData.Item(1)._infoName.ToString()
            TextBox3.Text = infoData.Item(2)._infoID.ToString() & " " & infoData.Item(2)._infoName.ToString()
        End Sub
    End Class 

    Yes i know but i thought you might have Information Class. see this example............

    Hope this helps............

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 3, 2009 9:35 AM