怎么设定GridView每一列宽度

时间:2022-09-13 23:17:14
怎么设定GridView每一列宽度[img=http://b304.photo.store.qq.com/psb?/V11UTVHC0wOXFp/kvv.7vVkBtpgehdXnDsBGvSqipCKvLUNhzTwY.oWibg!/b/YUb7PrUdlwAAYsRKNLVOlgAA][/img]当我点击编辑时出现了这种情况 更新
                                                         取消
我想让GridView的某一列宽度加大。

7 个解决方案

#1


编辑列  里面有宽度啊高度啊 颜色啊 随意调

#2


 <asp:BoundField DataField="OrderDate" HeaderText="下单日期" SortExpression="OrderDate"
                    HeaderStyle-Width="60px"></asp:BoundField>

#3


引用 2 楼  的回复:
<asp:BoundField DataField="OrderDate" HeaderText="下单日期" SortExpression="OrderDate"
  HeaderStyle-Width="60px"></asp:BoundField>



HeaderStyle-Width="60px"这个属性

#4




protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)
             || e.Row.RowState == DataControlRowState.Edit)
        {
            TextBox curText;
            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                if (e.Row.Cells[i].Controls.Count != 0)
                {
                    curText = e.Row.Cells[i].Controls[0] as TextBox;
                    if (curText != null)
                    {
                        curText.Width = Unit.Pixel(70);
                    }
                }
            }
        }   

    }

#5


引用 4 楼  的回复:
C# code


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)
             ||……

++1

#6


前台就是这样子了
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
           <Columns>
            <asp:TemplateField HeaderStyle-Width="200px" HeaderText="第一列">
                <ItemTemplate>
                    这是第一列
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderStyle-Width="50px" HeaderText="第二列">
                <ItemTemplate>
                    这是第二列
                </ItemTemplate>
            </asp:TemplateField>
           </Columns>
 </asp:GridView>

后台设置宽度,就是4楼了,支持4楼。

#7


该回复于2013-09-03 11:12:55被管理员删除

#1


编辑列  里面有宽度啊高度啊 颜色啊 随意调

#2


 <asp:BoundField DataField="OrderDate" HeaderText="下单日期" SortExpression="OrderDate"
                    HeaderStyle-Width="60px"></asp:BoundField>

#3


引用 2 楼  的回复:
<asp:BoundField DataField="OrderDate" HeaderText="下单日期" SortExpression="OrderDate"
  HeaderStyle-Width="60px"></asp:BoundField>



HeaderStyle-Width="60px"这个属性

#4




protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)
             || e.Row.RowState == DataControlRowState.Edit)
        {
            TextBox curText;
            for (int i = 0; i < e.Row.Cells.Count; i++)
            {
                if (e.Row.Cells[i].Controls.Count != 0)
                {
                    curText = e.Row.Cells[i].Controls[0] as TextBox;
                    if (curText != null)
                    {
                        curText.Width = Unit.Pixel(70);
                    }
                }
            }
        }   

    }

#5


引用 4 楼  的回复:
C# code


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
         if (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)
             ||……

++1

#6


前台就是这样子了
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
           <Columns>
            <asp:TemplateField HeaderStyle-Width="200px" HeaderText="第一列">
                <ItemTemplate>
                    这是第一列
                </ItemTemplate>
            </asp:TemplateField>
             <asp:TemplateField HeaderStyle-Width="50px" HeaderText="第二列">
                <ItemTemplate>
                    这是第二列
                </ItemTemplate>
            </asp:TemplateField>
           </Columns>
 </asp:GridView>

后台设置宽度,就是4楼了,支持4楼。

#7


该回复于2013-09-03 11:12:55被管理员删除