如何设置datatable列的宽度? [英] How to set width of datatable column ?

查看:4352
本文介绍了如何设置datatable列的宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Max-length作为列的宽度我尝试了但是它是snot工作,
行间距也没有工作

我想改变宽度第一列女巫是使用字符串构建器动态生成的数据库sp.append





我尝试过:



 foreach(dt2.Columns中的DataColumn列)
{
sb.Append(< th width =' 20%'style ='background-color:#e7e7e7; color:#000000'>);
sb.Append(column.ColumnName);
sb.Append(< / th>);
}
sb.Append(< / tr>);
foreach(dt2.Rows中的DataRow行)
{
sb.Append(< tr>);
foreach(dt2.Columns中的DataColumn列)
{
sb.Append(< td style ='font-size:12px; line-height:26px;'>) ;
sb.Append(row [column]);
sb.Append(< / td>);
}
sb.Append(< / tr>);
}

解决方案

DataTables,DataRows和DataColumns没有任何宽度或高度 - 它们不会直接呈现给用户并且没有UI - 宽度和高度仅与显示其包含的数据的演示控件有任何关联。



在这种情况下,您使用的是HTML表格显示您的数据,因此您(正确地)使用宽度设置,但您的格式错误: HTML th width属性 [ ^ ] - 20%需要双引号:

 sb.Append( < th width = \20%\style ='background-color:... 

或包含在CSS 样式中:

 sb.Append(< th style ='width:20%; background-color:... 


Quote:

我想改变第一列的宽度,使用字符串生成器动态生成数据库sp.append



  for  int  i =  0 ;我<  dt2.Columns.Count; i ++)
{
string width = i == 0 '50%' '20%'; // 第一列为50%,其他为20%
sb.Append( < th width = + width + style ='background-color:#e7e7e7; color:#000000'>);
sb.Append(dt2.Columns [i] .ColumnName);
sb.Append( < / th>);
}


Using Max-length for width of column i tried but it is snot working,
row-span is also not worked 

I want to change width of first column witch is dynamically generated from database using string builder sp.append



What I have tried:

foreach (DataColumn column in dt2.Columns)
                        {
                            sb.Append("<th width='20%' style = 'background-color: #e7e7e7;color:#000000'>");
                            sb.Append(column.ColumnName);
                            sb.Append("</th>");                            
                        }
                        sb.Append("</tr>");
                        foreach (DataRow row in dt2.Rows)
                        {
                            sb.Append("<tr>");
                            foreach (DataColumn column in dt2.Columns)
                            {
                                sb.Append("<td style='font-size:12px;line-height:26px;'>");
                                sb.Append(row[column]);
                                sb.Append("</td>");
                            }
                            sb.Append("</tr>");
                        }

解决方案

DataTables, DataRows, and DataColumns do not have any width or height - they are not directly presented to the user and have no UI - the width and height only have any relevance for the presentation controls which display the data they contain.

In this case, you are using HTML tables to display your data, so you are (correctly) using the th width setting, but you have the format wrong: HTML th width Attribute[^] - the 20% needs to be in double quotes:

sb.Append("<th width=\"20%\" style = 'background-color:...

Or included in the CSS style:

sb.Append("<th style='width:20%;background-color:...


Quote:

I want to change width of first column witch is dynamically generated from database using string builder sp.append


for (int i = 0; i < dt2.Columns.Count; i++)
            {
                string width = i == 0 ? "'50%'" : "'20%'"; // first column will be 50% and others 20%
                sb.Append("<th width=" + width+" style = 'background-color: #e7e7e7;color:#000000'>");
                sb.Append(dt2.Columns[i].ColumnName);
                sb.Append("</th>");
            }


这篇关于如何设置datatable列的宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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