简体   繁体   English

表间距问题

[英]Issue with table spacing

I've set-up a table that populates based on a stored procedure that runs. 我已经建立了一个基于运行的存储过程填充的表。 The width of the div that the table is contained in is 96% of the page. 表格所在的div宽度为页面的96%。 The width of the table is 100%. 桌子的宽度是100%。 The problem that I'm having is when I have two-three items populate the table there is a massive space in-between the items. 我遇到的问题是,当我有两三个项目填充表格时,项目之间存在很大的空间。 I specify the space in the table, but that isn't working. 我在表中指定了空间,但是这不起作用。 I'm also having issues with the font being black. 我也遇到黑色字体的问题。 I took all the CSS out that pertained to <a></a> hyperlinks, but it's still not displaying the correct font color. 我拿出了所有与<a></a>超链接有关的CSS,但它仍未显示正确的字体颜色。 Any suggestions? 有什么建议么?

 Dim con5 As New SqlConnection
    Dim cmd5 As New SqlCommand
    Dim index As Integer = 0
    Dim dt1 As New DataSet




    con5.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")
    con5.Open()
    cmd5.Connection = con5
    cmd5.CommandType = CommandType.StoredProcedure


    cmd5.CommandText = "ProductBreakdown"

    cmd5.Parameters.Add(New SqlParameter("ProductID", SqlDbType.Int)).Value = Session("Product")
    cmd5.Parameters.Add(New SqlParameter("DesignName", SqlDbType.VarChar, 50)).Value = Request.QueryString("o")




    Dim da1 As SqlDataAdapter = New SqlDataAdapter(cmd5)
    da1.Fill(dt1)

    Dim table1 As New HtmlTable

    Dim numells As Integer = 6


    dv = New DataView(dt1.Tables(0))
    Dim tablestring = ""
    Dim strTable As New StringBuilder()
    Dim rowIsOpen As Boolean = False
    Dim itmCounter As Integer = 0
    strTable.Append("<table width=""100%"" ""cellspacing=10px"" ""cellpadding=10px""> ")

    For Each dr As DataRowView In dv



        Dim crossover As String = dr("CrossoverID").ToString()
        Dim picid As String = dr("Description").ToString()
        Dim picdescrip As String = dr("DesignColor").ToString().ToUpper()
        Dim collectionname As String = dr("CollectionDescription").ToString().ToUpper()
        Dim designinfo As String = dr("DesignName").ToString()
        Session("Collection") = dr("CollectionDescription").ToString()
        'collectionname.ToUpper()
        ' For every 5 items create a new row.
        If itmCounter Mod 4 = 0 Then
            ' Since we want new row, first close any open row
            If rowIsOpen Then strTable.Append("</tr>")

            ' Start a new row and mark row as open so we can keep track
            strTable.Append("<tr>")
            rowIsOpen = True
        End If


        strTable.Append("<td><a href=""Sheet Vinyl Tile Product Page.aspx?p=" & crossover & "&o=" & designinfo & """>")
        strTable.Append("<img src=""Images/Products/" + picid + ".jpg""width=""188"" height=""188"" border=""0"""" /><br/><br/>")
        strTable.Append("<b><color=Black>" & collectionname & "</b><br />")
        strTable.Append(picdescrip & "</a></td>")

        itmCounter += 1

    Next
    ' Next

    ' Make sure we close any open rows
    If rowIsOpen Then strTable.Append("</tr>")

    If strTable.Length > 0 Then
        product.InnerHtml = "<table>" & _
            strTable.ToString() & _
            "</table>"
    End If

Tables have a specific role in HTML but you may want to use DIVs in this circumstance. 表在HTML中具有特定的作用,但是您可能需要在这种情况下使用DIV。 DIVs will automatically float and reposition themselves based on the width of the browser. DIV将根据浏览器的宽度自动浮动并重新定位。

Here is a example in jsFiddle 这是jsFiddle中的示例

HTML 的HTML

<div class="table">
    <div class="banner">The preferred developer response</div>
    <div class="cell">
        <img src="happy-icon.png">
    </div>
    ... 
    <div class="banner">Other emotions</div>
    <div class="cell">
        <img src="sad-icon.png">
    </div>
...
</div>

CSS 的CSS

.table {
    margin-left: 50px;
    margin-right: 50px;
}
.banner {
    padding: 10px;
    margin-top: 20px;
    clear: both;
    background-color: #336699;
    color: white;
    font-weight: bold;
}
.cell {
    width:   150px;
    float: left;
}

Your code may look like this 您的代码可能如下所示

Dim con5 As New SqlConnection
Dim cmd5 As New SqlCommand
Dim index As Integer = 0
Dim dt1 As New DataSet

con5.ConnectionString = ConfigurationSettings.AppSettings("ConnectionString")
con5.Open()
cmd5.Connection = con5
cmd5.CommandType = CommandType.StoredProcedure
cmd5.CommandText = "ProductBreakdown"
cmd5.Parameters.Add(New SqlParameter("ProductID", SqlDbType.Int)).Value = Session("Product")
cmd5.Parameters.Add(New SqlParameter("DesignName", SqlDbType.VarChar, 50)).Value = Request.QueryString("o")


Dim da1 As SqlDataAdapter = New SqlDataAdapter(cmd5)
da1.Fill(dt1)

dv = New DataView(dt1.Tables(0))

Dim strTable As New StringBuilder()
Dim itmCounter As Integer = 0
strTable.Append("<div class=""table""> ")

For Each dr As DataRowView In dv

    Dim crossover As String = dr("CrossoverID").ToString()
    Dim picid As String = dr("Description").ToString()
    Dim picdescrip As String = dr("DesignColor").ToString().ToUpper()
    Dim collectionname As String = dr("CollectionDescription").ToString().ToUpper()
    Dim designinfo As String = dr("DesignName").ToString()
    Session("Collection") = dr("CollectionDescription").ToString()

    strTable.Append("<div class=""cell""><a href=""Sheet Vinyl Tile Product Page.aspx?p=" & crossover & "&o=" & designinfo & """>")
    strTable.Append("<img src=""Images/Products/" + picid + ".jpg""width=""188"" height=""188"" border=""0"""" /><br/><br/>")
    strTable.Append("<b><color=Black>" & collectionname & "</b><br />")
    strTable.Append(picdescrip & "</a></div>")

    itmCounter += 1

Next
strTable.Append("</div>")
product.InnerHtml = strTable.ToString()

Same great taste but fewer calories 味道一样,卡路里却更少

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM