setting the width of the grid view column to dynamic without compromising the minimum width for the control

你说的曾经没有我的故事 提交于 2019-12-10 10:54:59

问题


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>

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?


回答1:


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;
        } 


来源:https://stackoverflow.com/questions/23423075/setting-the-width-of-the-grid-view-column-to-dynamic-without-compromising-the-mi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!