如何修复ASP.net gridview列宽? [英] How do I fix the ASP.net gridview column width?

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

问题描述

我希望我的网格单元格大小固定,目前超过数据长度



i want my grid cell in some fixed size currently it exceeds up to the data length

<asp:GridView AutoGenerateColumns="false" ID="grdselectTemplate" runat="server" AllowPaging="true"

         PageSize="10" EmptyDataText="No Record Found" Style="overflow: hidden;" OnRowDataBound="grdselectTemplate_RowDataBound">
         <Columns>

             <asp:TemplateField HeaderText="test">
                 <ItemTemplate>
                     <asp:RadioButton ID="rdbUser" runat="server" />
                 </ItemTemplate>
             </asp:TemplateField>

             <asp:BoundField DataField="Name" HeaderText="Template Name" ItemStyle-Width="100" />


 also i tryed this in code behind page 


 protected void grdselectTemplate_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.Header)
        {
             
            e.Row.Cells[1].Attributes["width"] = "50px";
            e.Row.Cells[2].Attributes["width"] = "10px";
        }
 
    }

推荐答案

选项1)添加CssClass,在其中定义max-width和宽度(并将其设置为列当然)。



选项2)向asp:radiobutton元素添加所需宽度,并使列按元素宽度调整大小
option 1) Add CssClass in which you define max-width and width (and set it to the column of course).

option 2) Add needed width to asp:radiobutton element and leave the column to resize by the element width


只需添加一个定义宽度的CssClass。



如果你正在尝试使用代码(不建议)

Simply add a CssClass with defined width.
OR
If you are trying with code behind (not suggesting)
grdselectTemplate.Columns[1].ItemStyle.Width=100; //Set your column no. according to your grid


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

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