Thanks for the links you sent. Actually, i found that something in my form is missing, thats why my application is not giving me the result i desire. Let me explain my application. I have a listbox control whose items are bound to a datatable. I have also a textbox in my form, which is initially blank.Then i select an item from the listbox, and then i want to display the selected item in the textbox.So, i wrote the following code.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
Dim conn As SqlConnection
Dim cmdSelect As SqlCommand
Dim dtr As SqlDataReader
Dim ds As DataSet
conn = New SqlConnection("Server=cabin61;UID=sa;PWD=;Database =ab")
conn.Open()
cmdSelect = New SqlCommand("Select rollno From chkbtry", conn)
dtr = cmdSelect.ExecuteReader()
ListBox1.DataSource = dtr
ListBox1.DataTextField = "rollno"
ListBox1.DataBind()
dtr.Close()
conn.Close()
End If
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox1.Text = ListBox1.SelectedItem.Value
End Sub
<asp:listbox id="ListBox1" style="Z-INDEX: 102; LEFT: 345px; POSITION: absolute; TOP: 101px" runat="server" Width="158px" Height="35px" AutoPostBack="True"></asp:listbox>
<asp:textbox id="TextBox1" style="Z-INDEX: 103; LEFT: 347px; POSITION: absolute; TOP: 167px" runat="server"></asp:textbox>
But it is not working.Is there anything mising in the code ? Should some properties of the listbox have to be changed ? Please advice
|