将网格视图列的宽度设置为动态而不会影响控件的最小宽度 [英] setting the width of the grid view column to dynamic without compromising the minimum width for the control

查看:114
本文介绍了将网格视图列的宽度设置为动态而不会影响控件的最小宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

I'm using

<asp:GridView ID="Grid1"  runat="server" AutoGenerateColumns="False"  BorderWidth="0px" BorderColor="white" BorderStyle="Solid">

<asp:TemplateField HeaderText="tf1" ControlStyle-Width="40px">  
<ItemTemplate>    
<asp:Label ID="lbl1" runat="server" Text='<%# String.Format("{0:###,###,###,##0}",Convert.ToInt64(DataBinder.Eval(Container.DataItem,"tf1"))) %>' />
<asp:TextBox id="txt1" runat="server" Text='<%# Eval("tf1") %>'  style="display:none;text-align:right;" MaxLength = "9"  />  
</ItemTemplate>                                         
</asp:TemplateField> 

</asp:GridView>

问题是,尽管ConrolStyle-Width设置为40 px,我希望它是动态的大小来容纳需要超过40px空间的数据。我怎么才能做到这一点?

The problem is eventhough the ConrolStyle-Width is set to 40 px, I want it to be dynamic in size to accomodate data which requires more than 40px space. How can I achieve this?

推荐答案

而不是设置ControlStyle-Width =40px只需像这样设置css类: p>

Instead of setting ControlStyle-Width="40px" just set css class like this:

ControlStyle-CssClass="template"

然后根据需要设置字段样式。您可以添加最小宽度,这意味着所有字段的最小宽度都等于指定的宽度,如果内容宽度大于字段宽度,则会适合它的内容。

and then style your fields as you want. You can add min-width which means all fields will have minimum width equal to specified and if content width is larger than field width will fit it content.

.template{
            min-width: 40px;
        } 

这篇关于将网格视图列的宽度设置为动态而不会影响控件的最小宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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