Hello guys,
AM trying to on page load, load all product IDs from database to dropsown list, and the on selecting anyone of the IDs, fetch data from the database, and fill textboxex on the webpage.
CAn you help me pls
2 replies to this topic
#1
Posted 07 May 2010 - 12:02 AM
|
|
|
#2
Posted 07 May 2010 - 03:06 AM
could you post the code that you have worked until now , so that if there are corrections we can help you:)
#3
Posted 07 May 2010 - 04:54 AM
I found the solution
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
DDLDataSource()
End If
End Sub
Private Sub DDLDataSource()
Dim connString As String = "Your connection string"
Using conn As New SqlConnection(connString)
Dim queryString As String = "SELECT * FROM Products"
Dim comm As New SqlCommand(queryString, conn)
Dim da As New SqlDataAdapter(comm)
Dim dt As New DataTable()
da.Fill(dt)
DropDownList1.DataSource = dt
DropDownList1.DataTextField = "ProductName"
DropDownList1.DataValueField = "ProductID"
DropDownList1.DataBind()
End Using
End Sub
Private Sub FetchProductData()
Dim connString As String = "Your connection string"
Using conn As New SqlConnection(connString)
Dim queryString As String = "SELECT * FROM Products WHERE ProductID=@ProductID"
Dim comm As New SqlCommand(queryString, conn)
comm.Parameters.AddWithValue("ProductID", DropDownList1.SelectedItem.Value)
Dim da As New SqlDataAdapter(comm)
Dim dt As New DataTable()
da.Fill(dt)
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
TextBox1.Text = dt.Rows(0)("ProductID").ToString()
TextBox2.Text = dt.Rows(0)("ProductName").ToString()
TextBox3.Text = dt.Rows(0)("ProductCategoryName").ToString()
End If
End Using
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If DropDownList1.SelectedIndex <> -1 Then
FetchProductData()
End If
End Sub
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









