两次获得查询结果

| 你好 我在此页面上两次获得结果,我不确定为什么。当我在DropdownList1中选择Option 2后查询数据库时,结果出现两次。是否因为结果出现在更新面板中?非常感谢您的帮助。我看不到代码的问题,这让我发疯了! page.aspx
   <asp:DropDownList ID=\"DropDownList1\" runat=\"server\" AutoPostBack=\"true\" OnSelectedIndexChanged=\"DropDownList1_SelectedIndexChanged\">
<asp:ListItem Value=\"Select\">Select</asp:ListItem>
 <asp:ListItem value=\"Option 1\">Option 1</asp:ListItem>
   <asp:ListItem Value=\"Option 2\">Option 2</asp:ListItem>
</asp:DropDownList>


   <asp:UpdatePanel id=\"FirstPanel\" runat=\"server\" RenderMode=\"Inline\">
   <ContentTemplate>   
      <div id=\"tohide1\" visible=\"False\" runat=\"server\"> 
           +++Do something+++
           </div>

<div id=\"tohide2\" visible=\"false\" runat=\"server\"> 
    <asp:Label ID=\"Label1\" runat=\"server\"></asp:Label>
   </div>

   </ContentTemplate>
   <Triggers>
   <asp:AsyncPostBackTrigger ControlID=\"DropDownList1\" EventName=\"SelectedIndexChanged\"></asp:AsyncPostBackTrigger>
    </Triggers>
    </asp:UpdatePanel>
page.aspx.vb
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
    If DropDownList1.SelectedValue = \"Option 1\" Then

        tohide1.Visible = \"True\"
        tohide2.Visible = \"False\"

    ElseIf DropDownList1.SelectedValue = \"Option 2\" Then

        tohide1.Visible = \"False\"
        tohide2.Visible = \"True\"

     Dim connectionString As String = ConfigurationManager.ConnectionStrings(\"myConnString\").ToString()
        Dim SqlQuery As String

        SqlQuery = \"SELECT CourseCode, Q1 FROM Courses WHERE (Q1 = 1)\"

        Dim conn As SqlConnection = New SqlConnection(connectionString)
        Dim Cmd1 As SqlCommand = New SqlCommand(SqlQuery, conn)

        Try
            conn.Open()

            Dim myReader As SqlDataReader = Cmd1.ExecuteReader


            While myReader.Read()

                Dim CourseCode As String = myReader(\"CourseCode\")

                Label1.Text += CourseCode & \"<br />\"

          End While

        Catch ex As SqlException
            lblmessage.Text = ex.Message()
        Finally
            conn.Close()
        End Try

    End If
End Sub
    
已邀请:
我将在过程顶部附近将Label1.Text重置为\“ \”。那应该停止结果的重复。     

要回复问题请先登录注册