0
' USED TO REFRESH THE PAGE WHIN IT IS POSTED BACK 
            If (IsPostBack = False) Then
                ' USED TO DISPLAY DEFAULT FIRST ITEM IN THE DROPDOWN 
                Dim Li1 As New ListItem()
                Li1.Text = "ALL"
                Li1.Value = ""
                cboStudy.Items.Add(Li1)
                ' USED TO COUNT THE STUDIES IN THE DROPDOWN 
                If (objDS.Tables(0).Rows.Count <> 0) Then
                    ' USED TO CIRCULATE LOOP UPTO THE RECORD COUNT
                    Dim i As Integer
                    For i = 0 To objDS.Tables(0).Rows.Count - 1
                        ' USED TO CREATE NEW ITEM IN THE DROPDOWN 
                        Dim Li As New ListItem
                        Li.Text = objDS.Tables(0).Rows(i)("Study_Desc").ToString()
                        Li.Value = objDS.Tables(0).Rows(i)("Study_ID").ToString()
                        'USED TO ADD ITEMS IN THE DROPDOWN 
                        cboStudy.Items.Add(Li)
                    Next
                End If
                'USED TO SAVE THE CHANGES IN DATASET  
                objDS.AcceptChanges()
                ' USED TO CLOSE THE DATABASE CONNECTION 
                objDS.Dispose()
            End If
        End If

I have to read dataset in javascript. So that I have to bind Study_Desc in DropDownList.

How can I do that?

Josh Darnell
  • 11,304
  • 9
  • 38
  • 66
harsh
  • 109
  • 1
  • 6
  • 22
  • why do you want to read your data-set in JavaScript? The question is unclear what you are looking for? – ankur Mar 12 '12 at 11:07
  • yes i have to read dataset in javascript object and then bind data in dropdownlist.. – harsh Mar 12 '12 at 11:21

1 Answers1

1

I believe you might find it useful to review how an ASP.NET page works and how it renders. In your particular case you are setting the contents of a dropdownlist to your dataset. This will then render a 'select' object to the user with the appropriate entries without the need for Javascript. This all occurs on the server-side, which is processed on the server before a HTML response to given back to the user.

With Javascript, this code runs on the client-side, i.e. the user's computer. Here it is possible to retreive your dataset (by this, the dataset will get serialised to be passed over the wire and read into a format that Javascript can read) and have it interact on the client-side. The question is, in your case, is why bother as you're rendering the dropdown on the server-side. If you are interested in pushing your dataset to Javascript, check out the links on this post for a selection of approaches you can take.

Minor notes:

In your code you're using the 'AcceptChanges' method when there is absolutely no reason to use this unless you're making a change(s) to the dataset which I'm guessing you're not in the PageLoad...

Community
  • 1
  • 1
SeanCocteau
  • 1,838
  • 19
  • 25