如何在使用<asp:placeholder> </asp:placeholder>时将数据并排显示

时间:2014-10-28 11:18:15

标签: asp.net oracle visual-studio

您能否使用visual studio 2013和asp.net帮助我浏览我的搜索页面。

我有一个简单的文本框和一个按钮,因此用户可以在数据库中搜索名称,我想要做的是当点击搜索按钮时,结果并排显示在同一页面上,就好像像一张桌子。

当我在此时进行搜索时,它会像这样显示在彼此之下..

James
30
Male
Programming

但我试图表现出来......

James 30 Male Programming

有人可以告诉我我哪里出错了。谢谢

Dim dsResults As New DataSet
    Dim dt As DataTableReader



    dsResults = SearchResults(sbox1.Text)
    dt = dsResults.CreateDataReader


    Dim tb As New Table
    Dim tr As New TableRow
    Dim tc As New TableCell
    Dim lb As New Label



    If dt.HasRows = True Then
        Do While dt.Read

            tr = New TableRow
            tc = New TableCell
            lb = New Label

            lb.Text = dt.Item("name").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)

            tb.Controls.Add(tr)


            tr = New TableRow
            tc = New TableCell
            lb = New Label

            lb.Text = dt.Item("age").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)

            tb.Controls.Add(tr)


            tr = New TableRow
            tc = New TableCell
            lb = New Label

            lb.Text = dt.Item("sex").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)

            tb.Controls.Add(tr)


            tr = New TableRow
            tc = New TableCell
            lb = New Label

            lb.Text = dt.Item("department").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)

            tb.Controls.Add(tr)


            tr = New TableRow
            tc = New TableCell
            lb = New Label

            lb.Text = dt.Item("list_group").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)

            tb.Controls.Add(tr)


            tr = New TableRow
            tc = New TableCell
            lb = New Label

            lb.Text = dt.Item("date_added").ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)

            tb.Controls.Add(tr)
        Loop
        dt.Close()
        dsResults.Dispose()

        placeResults.Controls.Add(tb)

    Else

        noResultOutput.Text = "No Results Matched Your Search"

    End If

1 个答案:

答案 0 :(得分:0)

不是将所有内容添加到同一个元素中,而是为自己添加更多单元格,并且只为每个WHILE循环添加一行。

用较少详细的方法编辑......

    Dim colList() As String = {"name", "age", "sex"}

    Do While dt.Read
        Dim tr As New TableRow

        For Each col As String In colList
            Dim tc As New TableCell

            lb.Text = dt.Item(col).ToString()
            tc.Controls.Add(lb)
            tr.Controls.Add(tc)
        Next

        tb.Controls.Add(tr)
    Loop