.net 动态列宽

.net 动态列宽,.net,asp.net,.net,Asp.net,问题:如何在我的网格中设置列的宽度 asp: protected void GridView1_DataBound(object sender, EventArgs e) { if (GridView1.Columns.Count!=0) GridView1.Columns[0].ItemStyle.Width = 800; 如果你总是想要相同的宽度,我会用CSS。您可以这样做: .wide { border:3px solid black; width:400px;

问题:如何在我的网格中设置列的宽度

asp:

protected void GridView1_DataBound(object sender, EventArgs e)
{
    if (GridView1.Columns.Count!=0)
        GridView1.Columns[0].ItemStyle.Width = 800;

如果你总是想要相同的宽度,我会用CSS。您可以这样做:

.wide  {
border:3px solid black;
width:400px;
}
css-content.css (строка 778)
from tr
element.style {
color:#333333;
}
from table#ctl00_ContentPlaceHolder1_GridView1
element.style {
border-collapse:collapse;
color:#333333;
}
from div#ctl00_ContentPlaceHolder1_Panel1
element.style {
border-style:outset;
}
from body
body {
color:#666666;
font-family:Verdana,Arial,Helvetica,sans-serif;
font-size:0.7em;
line-height:1.4em;
}
.wide { width: 400px; }
在CSS中:

GridView1.Columns[0].ItemCssClass = "wide";
如果设置项目样式的宽度,则该列中的每个单元格的css id都会在html中重复,这样至少可以减少标记

如果您使用的是自动生成的列,那么实际的列集合为空,您需要像下面这样连接到RowDataBound事件:

.wide  {
border:3px solid black;
width:400px;
}
css-content.css (строка 778)
from tr
element.style {
color:#333333;
}
from table#ctl00_ContentPlaceHolder1_GridView1
element.style {
border-collapse:collapse;
color:#333333;
}
from div#ctl00_ContentPlaceHolder1_Panel1
element.style {
border-style:outset;
}
from body
body {
color:#666666;
font-family:Verdana,Arial,Helvetica,sans-serif;
font-size:0.7em;
line-height:1.4em;
}
.wide { width: 400px; }

在GridView标记中添加
OnRowDataBound=“GridView1\u RowDataBound”

如果您总是想要相同的宽度,我会使用CSS。您可以这样做:

.wide  {
border:3px solid black;
width:400px;
}
css-content.css (строка 778)
from tr
element.style {
color:#333333;
}
from table#ctl00_ContentPlaceHolder1_GridView1
element.style {
border-collapse:collapse;
color:#333333;
}
from div#ctl00_ContentPlaceHolder1_Panel1
element.style {
border-style:outset;
}
from body
body {
color:#666666;
font-family:Verdana,Arial,Helvetica,sans-serif;
font-size:0.7em;
line-height:1.4em;
}
.wide { width: 400px; }
在CSS中:

GridView1.Columns[0].ItemCssClass = "wide";
如果设置项目样式的宽度,则该列中的每个单元格的css id都会在html中重复,这样至少可以减少标记

如果您使用的是自动生成的列,那么实际的列集合为空,您需要像下面这样连接到RowDataBound事件:

.wide  {
border:3px solid black;
width:400px;
}
css-content.css (строка 778)
from tr
element.style {
color:#333333;
}
from table#ctl00_ContentPlaceHolder1_GridView1
element.style {
border-collapse:collapse;
color:#333333;
}
from div#ctl00_ContentPlaceHolder1_Panel1
element.style {
border-style:outset;
}
from body
body {
color:#666666;
font-family:Verdana,Arial,Helvetica,sans-serif;
font-size:0.7em;
line-height:1.4em;
}
.wide { width: 400px; }

在GridView标记中添加
OnRowDataBound=“GridView1\u RowDataBound”

请说明您的问题,我不明白您在问什么。请说明您的问题,我不明白您在问什么。GridView1.Columns[0]。ItemCss…//没有此类参数,即使此处也没有列:(@nCdy-如果您动态生成列,则不会有任何列,并且您需要绑定到RowDataBound,我将使用example@nCdy-这并不是那么慢…当你考虑一个页面碰到服务器时运行什么,这是一个非常,非常,非常小的部分代码运行。,它没有效果,它出错了?如果没有效果,您添加了css类了吗?查看标记以查看是否添加了class属性。添加了css类,我可以在firefox插件的目标列上看到它,甚至可以在那里更改它,但它没有效果…GridView1.Columns[0].ItemCss…//没有这样的参数,甚至这里也没有列:(@nCdy-如果您动态生成列,则不会有任何列,并且您需要绑定到RowDataBound,我将使用example@nCdy-这并不是那么慢…当你考虑一个页面碰到服务器时运行什么,这是一个非常,非常,非常小的部分代码运行。,它没有效果,它出错了吗?如果没有效果,你添加了css类了吗?看看标记,看看是否添加了class属性。添加了css类,我可以在firefox插件的目标列上看到它,我甚至可以在那里更改它,它没有效果。。。