I am having trouble to collect the value of a listbox which user selected. But I have not problem to collect the values of my other control objects. Could anyone see why this happening? Thanks. Exception Details: System.NullReferenceException: Object reference
not set to an instance of an object. response.write (lstServerNames1.SelectedItem.Text)//this is where I got error lstServerNames1 is a listbox I created, it is populated with an Access table. I was using the DataSet to populate it and it is populated correctly
when page is first loaded. but when user selects one item from this list, and I want to retrive the value whatever user selected, then I got error. Isn't the "lstServerNames1.SelectedItem.Text" the right syntax to get lstServerNames1's value? Or something
else causing the problem? ================here is how I created this control============================= ==============here is how I populated this list============== dim conStr as String = "Provider=Microsoft.JET.OLEDB.4.0;data source=c:\Databases\SERVERS.mdb"
dim conn as OleDbConnection = New OleDbConnection(conStr) dim sqlStr = "select id, server_name FROM SERVERS" dim da as OleDbDataAdapter = new OleDbDataAdapter(sqlStr, conn) dim ds as DataSet = new DataSet() da.Fill(ds, "servers") dim dv as DataView = ds.Tables("SERVERS").DefaultView
lstServerNames1.DataSource = dv lstServerNames1.DataBind() conn.Close
calliawang
Member
295 Points
59 Posts
trouble to get the selected item value from a listbox control
Aug 06, 2003 02:46 PM|LINK