This is a migrated thread and some comments may be shown as answers.

ListBox system.data.datarowview

1 Answer 21 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Allan
Top achievements
Rank 2
Allan asked on 14 Oct 2011, 05:52 PM
I am sure I am missing something simple here.

I have created a function to call a storeproc and want to return the results to a listbox:

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    rgd_CurrentGroups.DataSource = GetGroups()
    rgd_CurrentGroups.DataBind()
    RadListBox1.DataSource = GetGroups().DefaultView
    RadListBox1.DataBind()
End Sub
Private Function GetGroups() As DataTable
    'Dim UserName As String = Request.QueryString("UserName")
    Dim UserName As String = "fred"
    Dim connectionString As String = DirectCast(ConfigurationManager.ConnectionStrings("IT_CentralConnectionString").ConnectionString, String)
    Dim connection As New SqlConnection(connectionString)
    Dim command As New SqlCommand(connectionString, connection)
    command = New SqlCommand("procGetGroupUsers", connection)
    command.CommandType = CommandType.StoredProcedure
    command.Parameters.Add("@UserName", SqlDbType.VarChar).Value = UserName
    command.Connection.Open()
    Dim myDataAdapter As New SqlDataAdapter(command)
    Dim myDataSet As New DataSet
    Dim dtData As New DataTable
    myDataAdapter.Fill(myDataSet)
    Return myDataSet.Tables(0)
    command.Connection.Close()
End Function

If I use a radgrid the grid populates correctly but if I use a listbox the funtion only returns system.data.datarowview.

Can some one please set me straight.

Thank you.


1 Answer, 1 is accepted

Sort by
0
Allan
Top achievements
Rank 2
answered on 14 Oct 2011, 09:28 PM
Duh...

Figured it out.

Just needed to add the field name I am returning from the StoredProc to the DataValueField Setting.
Tags
ListBox
Asked by
Allan
Top achievements
Rank 2
Answers by
Allan
Top achievements
Rank 2
Share this question
or