简体   繁体   English

GridView列不更改宽度大小

[英]Gridview column not changing width size

I can't make this GridView column change its width, I have tried this: 我无法使此GridView列更改其宽度,我已经尝试过:

<asp:BoundField DataField="ABC" HeaderText="ABC" SortExpression="ABC"  ControlStyle-Width="200%">

Or as pixels: 或以像素为单位:

<asp:BoundField DataField="ABC" HeaderText="ABC" SortExpression="ABC"  ControlStyle-Width="500px">

Or this inside the Boundfield tags: 或者在Boundfield标签内:

<ItemStyle HorizontalAlign="Center" Width="500px"/>

Also tried this on code-behind: 还尝试了代码隐藏:

Protected Sub GridView3_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView3.RowDataBound
    e.Row.Cells(7).Width = 500
End Sub

How do I get it right? 我该如何正确处理?

Here is how it can be done. 这是可以完成的。 I am re-sizing the columns who having property : Visible = True 我正在调整具有属性的列的大小:Visible = True

Private Sub GridViewColumnsrResize(ByVal aspectratio As Integer, ByVal gv As DataGridView)
    Try
        Dim col_count As Integer = gv.Columns.Count
        For j As Integer = 0 To col_count - 1
            If gv.Columns(j).Visible = True Then
                gv.Columns(j).Width = gv.Columns(j).Width * aspectratio
            End If
        Next
    Catch ex As Exception
        'output ex
    End Try
End Sub

I just posted this related thread yesterday with a similar issue. 我昨天刚刚发布了一个与此类似的问题相关的主题。 Short answer is you can't. 简短的答案是你不能。 There is a workaround as noted in this thread (at the bottom): 如该线程所述(在底部),有一种解决方法:

How can I print a full gridview area via a custom print window? 如何通过自定义打印窗口打印整个gridview区域?

Suggestion if you want the value to come in one line , for that you are increasing width then you can try this: 建议 ,如果你想要的值来在同一行,为要增加宽度,那么你可以试试这个:
add a cssClass to you Gridview like cssClass=gridContainer , cssClass=gridContainer cssClass向您的Gridview添加一个cssClass
add in the .css file: .css文件中添加:

 .gridContainer
  {
     white-space:nowrap;
  }

for more option, look white-space property 有关更多选项,请查看空白属性

我通过为GridView本身设置固定宽度来解决此问题,它可能不是为特定列设置的,但是它在所有GridView列之间共享其宽度,从而扩展了我想扩展的列。

<asp:GridView ID="GridView3" runat="server" DataSourceID="SqlDataSource4" AutoGenerateColumns="False" CssClass="Gridview" Width="800px">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM