Re: Selected Item in ListBox

Tech-Archive recommends: Fix windows errors by optimizing your registry



Many thanks, I realise I need the continuity of a Dataset. I have not
Datasets for a while, could you point me to a good article?

"Stan" wrote:

On 30 Mar, 19:07, EdwardH <Edwa...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
I am filling a ListBox from a stored proc and a SQLDataReader which works fine.

Private pCateg As SqlCommand
Private pDR as Data.Sql.SqlDataReader
pCateg = New SqlCommand("pLodge")
pCateg.CommandType = Data.CommandType.StoredProcedure
pDR = pCateg.ExecuteReader
ListBox1.DataSource = pDR
ListBox1.DataTextField = "Category"
ListBox1.DataValueField = "Category"
ListBox1.Databind

I am trying to use the Value/Text of the Selected Item but am failing to get
that value which is coming back as a Null:
ListBox1. SelectedValue

How should I test that an Item has been selected and then get the value for
further use?
With thanks

You are using the wrong type of object as a DataSource (It should
throw an exception).

Recommend a DataSet (one created in the App_Code folder as an XSD
file). Create a TableAdapter that uses the "pLodge" stored procedure
as its select command.

.



Relevant Pages

  • Re: Selected Item in ListBox
    ... "Stan" wrote: ... value back from ListBox using - "ListBox1.SelectedValue.ToString". ... Private pDR as Data.Sql.SqlDataReader ... populate the ListBox, make a selection in the browser, and then not ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Selected Item in ListBox
    ... Private pCateg As SqlCommand ... Private pDR as Data.Sql.SqlDataReader ... Create a TableAdapter that uses the "pLodge" stored procedure ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Re: Selected Item in ListBox
    ... Have achieved the filling of the ListBox with a DataSet but still cannot get ... Private pCateg As SqlCommand ... Private pDR as Data.Sql.SqlDataReader ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)
  • Selected Item in ListBox
    ... I am filling a ListBox from a stored proc and a SQLDataReader which works fine. ... Private pCateg As SqlCommand ... Private pDR as Data.Sql.SqlDataReader ... SelectedValue ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)