kahlua001 said:
No, you do not need db connectivity in javascript. You connect to the database in your codebehind, and write out the javascript arrays on the client, ready to use when needed.
I tried out with the following code,
I know that this causes page refresh,
can u provide me code or any sample how to access this in javascript
as i didn't use javascript till now.
, provided u r free.
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
'***************************************
' Variable Declaration
'***************************************
If Not Page.IsPostBack Then
Dim sqlCon As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlDr As SqlDataReader
' Creating Connection to the Database
sqlCon = New SqlConnection(ConfigurationSettings.AppSettings("dsn"))
sqlCon.Open()
sqlCmd = New SqlCommand("select Client from xyz", sqlCon)
sqlDr = sqlCmd.ExecuteReader
DropDownList1.DataSource = sqlDr
'Fetching clientid from the Database And assign them to the dropdown list
While sqlDr.Read
Dim newListItem As New ListItem
newListItem.Value = sqlDr.GetString(0)
DropDownList1.Items.Add(newListItem)
End While
sqlCon.Close()
End If
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
'***************************************
' Variable Declarations
'***************************************
Dim strStr1 As String
Dim strStr2 As String
Dim sqlCon As SqlConnection
Dim sqlCmd As SqlCommand
Dim sqlDr As SqlDataReader
strStr1 = DropDownList1.SelectedValue
strStr2 = "Some query"
' Establishing a connection to the database
sqlCon = New SqlConnection(ConfigurationSettings.AppSettings("dsn"))
sqlCon.Open()
sqlCmd = New SqlCommand(strStr2, sqlCon)
sqlDr = sqlCmd.ExecuteReader
dropdownlist2.Items.Clear()
dropdownlist2.DataSource = sqlDr
' Fetching records from the database and assign them to the dropdown control
While sqlDr.Read
Dim newlistitem1 As New ListItem
newlistitem1.Text = sqlDr.GetValue(0)
dropdownlist2.Items.Add(newlistitem1)
End While
End Sub