关于gridview调整列宽的问题
我是新手,最近在使用gridview时遇到了一个问题,困扰了我好几天。
为了让gridview支持滚动和单独刷新数据,利用ajax,将做好的用户控件(GridView放入UpdatePanel,外面再加上Panel 控件,设置 ScrollBar 为 both。
问题是不管如何设置,都不能控制每一列的宽度,感觉列宽就是根据header的文字宽度定的,换句话说如果字段名长点,那么这个列就宽些,不能用样式或者程序来自定义,这个问题是不是用了Panel控件造成的?
具体代码:其中MT_Name设置了宽度。
自定义控件部分:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FullGridView.ascx.cs"
Inherits="control_FullGridView" %>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" DataSourceID="SqlDataSource1" GridLines="None" AllowPaging="True" PageSize="5" AllowSorting="True" AutoGenerateColumns="False" >
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White"/>
<Columns>
asp:BoundField DataField="MT_ID" HeaderText="MT_ID"></asp:BoundField>
<asp:BoundField DataField="MT_Name" HeaderText="MT_Name">
<ItemStyle Width="100px" />
<HeaderStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="MT_MacType" HeaderText="MT_MacType"></asp:BoundField>
<asp:BoundField DataField="MT_IPAddr" HeaderText="MT_IPAddr" SortExpression="MT_IPAddr">
</asp:BoundField>
<asp:BoundField DataField="MT_Scan_A" HeaderText="MT_Scan_A"></asp:BoundField>
</Columns>
</asp:GridView>
显示部分:其中FullGridView就是自定义的gridview控件
<div id="rightbase" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Panel ID="GridPanel" runat="server" Height="350px" ScrollBars="Both" Width="780px" Wrap="false">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<uc1:FullGridView ID="FullGridView1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</div>