Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. record appear twice in dropdown list

record appear twice in dropdown list

Scheduled Pinned Locked Moved ASP.NET
questiondatabasesysadminhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LovelyHelp
    wrote on last edited by
    #1

    When I add a record to my drop down list on the same page, in my drop down list it will appear twice. What is my mistake? my code is like this ------------------------------------------------------- Protected Sub DoUploadChapter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myconnection As SqlConnection Dim mycommand As SqlCommand Message.InnerHtml = "" myconnection = New SqlConnection("Server=localhost;UID=sa;pwd=;database=u") mycommand = New SqlCommand("INSERT INTO t_linkChapter(link_chapter) VALUES (@ChapterName)", myconnection) mycommand.Parameters.Add("@chapterName", SqlDbType.VarChar, 50).Value = txtAddChapter.Text mycommand.Connection.Open() Try mycommand.ExecuteNonQuery() Message.InnerHtml = "Record Added
    " & mycommand.ToString() Catch Exp As SqlException If Exp.Number = 2627 Then Message.InnerHtml = "ERROR: A record already exists with the same name" Else Message.InnerHtml = "ERROR: Could not add record, please ensure the fields are correctly filled out" End If lblErrorChapter.Style("color") = "red" End Try mycommand.Connection.Close() LoadChapters() End Sub

    P 1 Reply Last reply
    0
    • L LovelyHelp

      When I add a record to my drop down list on the same page, in my drop down list it will appear twice. What is my mistake? my code is like this ------------------------------------------------------- Protected Sub DoUploadChapter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim myconnection As SqlConnection Dim mycommand As SqlCommand Message.InnerHtml = "" myconnection = New SqlConnection("Server=localhost;UID=sa;pwd=;database=u") mycommand = New SqlCommand("INSERT INTO t_linkChapter(link_chapter) VALUES (@ChapterName)", myconnection) mycommand.Parameters.Add("@chapterName", SqlDbType.VarChar, 50).Value = txtAddChapter.Text mycommand.Connection.Open() Try mycommand.ExecuteNonQuery() Message.InnerHtml = "Record Added
      " & mycommand.ToString() Catch Exp As SqlException If Exp.Number = 2627 Then Message.InnerHtml = "ERROR: A record already exists with the same name" Else Message.InnerHtml = "ERROR: Could not add record, please ensure the fields are correctly filled out" End If lblErrorChapter.Style("color") = "red" End Try mycommand.Connection.Close() LoadChapters() End Sub

      P Offline
      P Offline
      PrakashBhaskar
      wrote on last edited by
      #2

      you can check wethere the page is post for the first time or round trip use ispostback property to check this Thanks Warm Regards Prakash-B

      L 1 Reply Last reply
      0
      • P PrakashBhaskar

        you can check wethere the page is post for the first time or round trip use ispostback property to check this Thanks Warm Regards Prakash-B

        L Offline
        L Offline
        LovelyHelp
        wrote on last edited by
        #3

        my page load is like below..so should i change it to if postback then : : Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'set the panel of selection function to display pTitle.Visible = True pLesson.Visible = True pAdd.Visible = False 'pUpdate.Visible = False pAddChapter.Visible = False If Not IsPostBack Then LoadChapters() LoadTitle() End If lblAddInto.Text = "You are going to add New Title into " + ddlLesson.SelectedItem.Text + End Sub -- modified at 5:14 Thursday 16th March, 2006

        L 1 Reply Last reply
        0
        • L LovelyHelp

          my page load is like below..so should i change it to if postback then : : Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'set the panel of selection function to display pTitle.Visible = True pLesson.Visible = True pAdd.Visible = False 'pUpdate.Visible = False pAddChapter.Visible = False If Not IsPostBack Then LoadChapters() LoadTitle() End If lblAddInto.Text = "You are going to add New Title into " + ddlLesson.SelectedItem.Text + End Sub -- modified at 5:14 Thursday 16th March, 2006

          L Offline
          L Offline
          LovelyHelp
          wrote on last edited by
          #4

          It still don't work when i chage my if Not ispostback then to if ispostback. Some more it getting worst which effected my dropdownlsit. Is there other way?

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups