I have 4 text boxes. I enter a value in first text box. I want the next 3 text boxes populated values automatically from database based on value entered in the first text box. Can this be done in asp.net?
Ok, so we have a text box for say a "id' of some sort, like this:
<div style="text-align:right;width:300px">
Enter Hotel ID :<asp:TextBox ID="askHotel" runat="server" AutoPostBack="true"></asp:TextBox> <br />
<br />
Hotel Name :<asp:TextBox ID="txtHotel" runat="server" Width="180px"></asp:TextBox> <br />
City :<asp:TextBox ID="txtCity" runat="server" Width="180px"></asp:TextBox> <br />
Active :<asp:CheckBox ID="Active" runat="server" ></asp:CheckBox>
</div>
And our code is:
Protected Sub askHotel_TextChanged(sender As Object, e As EventArgs) Handles askHotel.TextChanged
Using cmdSQL As New SqlCommand("SELECT * FROM tblHotels WHERE ID = @ID",
New SqlConnection(My.Settings.TEST4))
cmdSQL.Parameters.Add("@ID", SqlDbType.Int).Value = askHotel.Text
cmdSQL.Connection.Open()
Dim rst As New DataTable
rst.Load(cmdSQL.ExecuteReader)
If rst.Rows.Count > 0 Then
With rst.Rows(0)
txtHotel.Text = .Item("HotelName")
txtCity.Text = .Item("City")
Active.Checked = .Item("Active")
End With
End If
End Using
End Sub
Output: