Hey there
i have been trying to bind a table from database to a listbox. I know this can be done quite easily but i keep having an error with i cannot figure out why.
Whenever i declare selectedMain as linklist.selectedItem.value, it will alsways tell me "Object reference not set to an instance of an object"
Please help me? thanks in advance
<script language="VB" runat="Server">
'path where xml file will be created
Sub page_Load(Sender as Object, E as EventArgs)
Dim ConODBC As new OdbcConnection
Dim cmdSelect as new OdbcCommand
Dim dsSet as new DataSet()
Dim dbApt as new OdbcDataAdapter
Dim dtrworks As OdbcDataReader
Dim connStr as String
connStr =""
ConODBC = New OdbcConnection(ConnStr)
conODBC.Open()
cmdSelect.Connection = ConODBC
cmdSelect.commandText = "select f_title, f_content from features_list"
dbApt.selectCommand = cmdSelect
dbApt.Fill(dsSet, "features_list")
'listbox-------------------------------------------------
Dim dtr as IDataReader = cmdSelect.executeReader()
linklist.DataSource = dtr
linklist.DataTextField = "f_title"
linklist.DataValueField = "f_title"
linklist.DataBind()
conODBC.Close
End Sub
'the upon click on the first listbox method__________________________
Sub linklist_SelectedIndexChanged(S as Object, E as EventArgs)
Dim ConODBC As new OdbcConnection
Dim cmdSelect as new OdbcCommand
Dim dsSet as new DataSet()
Dim dbApt as new OdbcDataAdapter
Dim dtrworks As OdbcDataReader
Dim connStr as String
connStr =""
ConODBC = New OdbcConnection(ConnStr)
conODBC.Open()
Dim selectedMain
selectedMain=linklist.selectedItem
selectedMain = linklist.selectedItem.value
testing.text = string.format("the selected one in listbox is" & selectedMain)
conODBC.Close
end sub
</script>
<html>
<head>
</head>
<body>
<form id="form1" runat="server">
<asp:ListBox BackColor="#CCCCCC" ID="linklist" Rows="5" runat="server" SelectionMode="single" AutoPostBack="true" OnSelectedIndexChanged="linklist_SelectedIndexChanged" target="_blank"/>
<asp:label ID="testing" runat="server"></asp:label>
</form>
</body>