我有一个像这样创建的 DataGrid:-
<asp:DataGrid id="myGrid"
BorderWidth="1"
CellPadding="3"
AutoGenerateColumns="true"
runat="server"
OnSelectedIndexChanged="myGridSelectedCallback">
<HeaderStyle CssClass="subHeader"></HeaderStyle >
<Columns>
<asp:ButtonColumn HeaderText=""
ButtonType="LinkButton"
Text="Display"
CommandName="Select">
</asp:ButtonColumn>
</Columns>
</asp:DataGrid>
并在代码隐藏中添加列,如下所示:-
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("MyCol", typeof(string)));
但是当我向其中添加行时,有时列中的文本会换行。似乎没有任何理由。该列的 MaxLength 为 -1,并且添加的字符串中没有换行符或其他控制字符。
我想要做的是加宽列以容纳其中最长的字符串(字符串只有约 20 个字符左右)。我在这方面找不到任何东西,因为其他人似乎都有相反的问题。
(此网格包含在 adiv
中,但div
没有最大宽度。)