动态设置Gridview中列的宽度 [英] dynamically set width of a column in Gridview
本文介绍了动态设置Gridview中列的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试动态设置gridview列的宽度,但是当我应用以下代码时,我看到浏览器没有变化。
.aspx代码是:
I am trying to dynamically set width of a gridview column but when I apply the following code, I see no change in the browser.
.aspx code is:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="5" CellSpacing="4" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" CellPadding="4" DataKeyNames="File_Name" GridLines="None" OnRowEditing="GridView1_RowEditing" OnRowDeleting="GridView1_RowDeleting" OnRowUpdated="GridView1_RowUpdated" OnRowUpdating="GridView1_RowUpdating" ForeColor="#333333" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnPageIndexChanging="GridView1_PageIndexChanging" AllowSorting="True" OnSorting="GridView1_Sorting" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_OnRowDataBound" >
<PagerSettings Mode="NumericFirstLast" FirstPageText="First" LastPageText="Last" PageButtonCount="10" Position="Bottom" />
<AlternatingRowStyle BackColor="White" />
<Columns >
<asp:TemplateField HeaderText="File">
<ItemTemplate>
<asp:LinkButton ID="lnkbtnFileName" runat="server" CommandArgument='<%# Eval("File_Name") %>' CommandName="Download" Text='<%# Eval("File_Name") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
.cs代码是:
.cs code is:
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
//SET WIDTH OF THE COLUMNS
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Width = Unit.Pixel(500); //DATE
e.Row.Cells[1].Width = Unit.Pixel(100); //CUSTOMER
e.Row.Cells[2].Width = Unit.Pixel(100); //DESTINATION
}
}
有人可以帮忙吗?
Can someone please help?
推荐答案
参考此链接---
http://www.aspdotnet-suresh.com/2013/01/aspnet-set-gridview-column-width.html [ ^ ]
你可以像这样设置
You can set it like this
GridView1.Columns[0].ItemStyle.Width = 50;
也请参阅这些链接
如何:动态设置GridView Web服务器控件列宽度
Asp.net在C#,VB.NET中动态设置Gridview列宽
这篇关于动态设置Gridview中列的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文