1 Replies - 1094 Views - Last Post: 14 October 2013 - 07:18 AM Rate Topic: -----

#1 rony patel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 14-October 13

Drop down list shows double

Posted 14 October 2013 - 06:05 AM

I am working on vb.net.When i try to bind data got from function to dropdownlist, its getting compiled successfully.when i save data first time after compiled it was save successfully but when i save next data at a time the drop-down list data are show double time. in every selection data loop round n round so please somebody help me.....

[start page load]
Private Sub Book_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
category()
searchcategory()
End Sub
[end page load]

Private Sub cat()
    Dim tbl As New DataTable
    Dim sql As String
    Dim dbobj As New DBClass
    sql = "select * from tblname"
    tbl = dbobj.GetRecords(sql)
    For i As Integer = 0 To tbl.Rows.Count - 1
        cmbcategory.Items.Add(tbl.Rows(i)("t"))
    Next
End Sub
Private Sub search_cat()
    Dim sql As String
    Dim tbl As New DataTable
    Dim obj As New DBClass
    sql = "select Name from tblname Where tablefield='" & cmbcategory.Text & "' "
    tbl = obj.GetRecords(sql)
End Sub

Private Sub cmbcate_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbcategory.SelectedIndexChanged
    category()
End Sub
Private Sub searchcat()
    cn.Open()
    Dim cmd As New SqlCommand("SELECT tblfield,frmname FROM tblname", cn)
    Dim ds As New DataSet
    Dim da As New SqlDataAdapter(cmd)
    da.Fill(ds, "My Data") 'list can be any name u want
    Dim col As New AutoCompleteStringCollection
    Dim i As Integer
    For i = 0 To ds.Tables(0).Rows.Count - 1
        col.Add(ds.Tables(0).Rows(i)("frmname").ToString())
    Next
    cmbcategory.AutoCompleteSource = AutoCompleteSource.CustomSource
    cmbcategory.AutoCompleteCustomSource = col
    cmbcategory.AutoCompleteMode = AutoCompleteMode.SuggestAppend
    cn.Close()
End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Drop down list shows double

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,311
  • Joined: 12-December 12

Re: Drop down list shows double

Posted 14 October 2013 - 07:18 AM

Please take the time to think of a sensible title for your question: "Problem" is obviously useless for any search purpose, and completely uninformative.

Where are your category() and searchcategory() functions? I thought you may have mis-typed and they were cat() and searchcat(), but your second code calls the function category().

[I hope that you haven't retyped this code? You should always post your actual code.]

Anyway, your SelectedIndexChanged event calls the function category(), which I assume will trigger the same event-call again.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1