表数据不受控制 [英] Table data are out of controll

查看:75
本文介绍了表数据不受控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HY!

我知道如何在html中使用表格,但我面临的错误是不可理解的...我知道如何在html中使用表格,但面对知道的错误对我来说是不可理解的......

这是我的代码...

HY!
I know how to use table in html very well, but the error iam facing know is un-understandable for me...I know how to use table in html very well, but the error iam facing know is un-understandable for me...
Here is my code...

<html>
<head>
<title>tets</title>
<style>
table
{
    border: 1px solid black;
    border-collapse: separate;
    border-spacing: 2px;
    border-color: gray;
    text-align: center;
    width: 500px;
    max-width: 500px;
}
th
{
    border-bottom:1px solid gray;
    border-spacing: 2px;
    padding-left: 15px;
    padding-right: 15px;
    text-align: center;
    background: silver;
}
td
{
    max-width:500px;
    background: silver;
}
.tbl
{
    margin-top:200px;
    margin-left: 230px;
}
</style>

</head>
<body>
    <div class="tbl">
<table>
    <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>UserName</th>
    <th>Email</th>
    <th>Password</th>
</tr>
    <tr>
        <td>Zaffar</td>
        <td>Khan</td>
        <td>MSZ</td>
        <td>M@yahoo.com</td>
        <td>123</td>
    </tr>
    <tr>
        <td>Zaffar</td>
        <td>Khan</td>
        <td>MSZ</td>
        <td>M@yahoo.com</td>
        <td>123</td>
    </tr>
    <tr>
        <td>Zaffar</td>
        <td>Khan</td>
        <td>MSZ</td>
        <td>M@yahoo.comgggggggggggggggggggggggggg</td>
        <td>123ggggggggggggggggggggggggggggggggggggggggggghjjjjjjjjjjjjjjjjjjjjjjfjyhfffffffffffffffffffffffffuyyyyyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</td>
    </tr>
</table>
</div>
</body>
</html>



错误是当我输入你上面看到的长数据并控制宽度时的表,然后数据将冲突,意味着数据超出单元格并越过宽度..请运行代码并检查是什么错误....

i想要的数据在表格和宽度i指定..


the error is when i enter the long data like you seen above and controll the width of the table, then the data will conflict, mean the data is out of cell and cross the width.. please run the code and check what is the error....
i want the data within the table and with a width i specifies..

推荐答案

因为长< TD>中没有空格字符标签,浏览器不知道在哪里包装内容。



选项1

这是如何处理数据库中的字符串值以插入< BR>的示例。标记每个这么多的字符并创建一个可以在HTML表格单元格中使用的新字符串。我使用20作为宽度值。这个样本是在VB中。您可以转换为您正在使用的任何语言。通过执行此操作,您不会修改数据库中的值。您正在处理要显示的数据,以使其正确显示。

Because you have no space characters in the long <TD> tags, the browser doesn't know where to wrap the contents.

Option 1
This is a sample of how a string value from the database can be processed to insert <BR> tags every so many characters and create a new string that can be used in the HTML table cell. I used 20 for the width value. This sample is in VB. You can convert to whatever language you are using. By doing this, you are not modifying the value in the database. You are processing the data for display so that it appears properly.
Dim strFromdatabase As String = "123ggggggggggggggggggggggggggggggggggggggggggghjjjjjjjjjjjjjjjjjjjjjjfjyhfffffffffffffffffffffffffuyyyyyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Dim strNewString As String ' New string to be output into the table cell
Dim x As Integer ' Number of characters left to process
Dim y As Integer ' Current index into source string
Dim z As Integer ' Number of characters to process this time through the loop
Const CELLWIDTH As Integer = 20
x = strFromdatabase.Length
y = 0
strNewString = ""
While x > 0
    z = Math.Min(CELLWIDTH, x)
    strNewString += strFromdatabase.Substring(y, z)
    x = x - z
    y = y + z
    If x > 0 Then
        strNewString += "<BR>"
    End If
End While
Debug.WriteLine(strNewString)







选项2

使用< TH>中的宽度属性和< TD>在样式表中标记或定义包含宽度属性的新样式,并将该样式用于电子邮件和密码列。








Option 2
Use the Width attribute in the <TH> and <TD> tags or define a new style in your stylesheet that contains the Width property and use that style for the Email and Password columns.


<tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>UserName</th>
    <th Width=100>Email</th>
    <th Width=100>Password</th>
</TR>


这篇关于表数据不受控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆