Hashtable输出在asp.net中重复

时间:2014-02-17 09:53:04

标签: asp.net

我已尝试使用以下代码将hashtable与listbox绑定。

的.aspx:

 <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Hashtable.aspx.vb" Inherits="Hashtable" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
            <br />
            <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox><br />
        </div>
        </form>
    </body>
    </html>

.aspx.vb

    #Region "Namespaces"

    Imports System.Data
    Imports System.IO
    Imports System.Net.Mail

    #End Region
    Partial Class Hashtable
        Inherits System.Web.UI.Page

        Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim ht As New Hashtable
            ht.Items.Add("1", "Sunday")
            ht.Items.Add("2", "Monday")
            ht.Items.Add("3", "Tuesday")
            ht.Items.Add("4", "Wednesday")
            ht.Items.Add("5", "Thursday")
            ht.Items.Add("6", "Friday")
            ht.Items.Add("7", "Saturday")

            For Each item In ht.Items

                ListBox1.Items.Add(item.key)
                ListBox1.Items.Add(item.value)

            Next    

        End Sub
    End Class

执行时,我得到以下输出:

列表框中的

 1 Sunday 2 Monday 3 Tuesday 4 Wednesday 5 Thursday 6 Friday 7 Saturday
 1 Sunday 2 Monday 3 Tuesday 4 Wednesday 5 Thursday 6 Friday 7 Saturday

为什么在我的代码中使用单个循环时它会出现两次?我该怎么做才能解决我的问题?

1 个答案:

答案 0 :(得分:1)

那样的东西?

select box_id,box_refid,box_value,effdate,closedate
from box_percent
union all
select box_id,box_refid,null,null,null
from box_percent
where closedate is not null