record appear twice in dropdown list
-
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 -
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 Subyou 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
-
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
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
-
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
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?