使用 Linq DataSource 在 Gridview 中自动换行
我在对 Gridview 进行自动换行时遇到问题。 Gridview 的源是在 LinqDataSourceLog_Selecting 方法中构建的 Linq Source。我有一列想要自动换行,但我想由于我绑定 Gridview 的方式,列数始终为 0,所以我无法换行我没有的内容。以下是网格的标记。
<asp:GridView ID="GridViewLog" Width="200px" runat="server" CellPadding="4" AllowPaging="true"
DataSourceID="LinqDataSourceLog" ShowHeader="true" AllowSorting="true" OnPageIndexChanging="GridViewLog_PageIndexChanging"
EnableModelValidation="True" AutoGenerateColumns="true" ForeColor="#333333" GridLines="Both"
Height="164px" OnRowDataBound="GridViewLog_RowDataBound" RowStyle-Wrap="true" AlternatingRowStyle-Wrap="true"
PageSize="10" PagerSettings-Mode="Numeric" OnPreRender="GridViewLog_Prerender">
<EmptyDataTemplate>
<table>
<tr>
<td style="color: #003366">
<strong>Either the applied filter returned no results or<br />
the Out of office log is currently empty .</strong>
</td>
</tr>
</table>
</EmptyDataTemplate>
<AlternatingRowStyle BackColor="White" Wrap="false" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" CssClass="pagination" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" Wrap="false" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
预先感谢您的帮助。
I'm having an issue with word wrapping a Gridview. The source for the Gridview is a Linq Source that is built in the LinqDataSourceLog_Selecting method. I have a column that I want to word wrap but I guess because of how I am binding the Gridview, the Column count is Always 0 so I can't wrap something I don't have. The following is the markup for the Grid.
<asp:GridView ID="GridViewLog" Width="200px" runat="server" CellPadding="4" AllowPaging="true"
DataSourceID="LinqDataSourceLog" ShowHeader="true" AllowSorting="true" OnPageIndexChanging="GridViewLog_PageIndexChanging"
EnableModelValidation="True" AutoGenerateColumns="true" ForeColor="#333333" GridLines="Both"
Height="164px" OnRowDataBound="GridViewLog_RowDataBound" RowStyle-Wrap="true" AlternatingRowStyle-Wrap="true"
PageSize="10" PagerSettings-Mode="Numeric" OnPreRender="GridViewLog_Prerender">
<EmptyDataTemplate>
<table>
<tr>
<td style="color: #003366">
<strong>Either the applied filter returned no results or<br />
the Out of office log is currently empty .</strong>
</td>
</tr>
</table>
</EmptyDataTemplate>
<AlternatingRowStyle BackColor="White" Wrap="false" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" CssClass="pagination" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" Wrap="false" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
thank you in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
网格视图中 Columns 集合的 Count 属性仅计算您在标记中指定的声明列的数量。当您指定
AutoGenerateColumns="true"
时,这些列将不会被计算在内。作为 GridViewLog.Columns.Count 的替代方案,使用 GridViewLog.HeaderRow.Cells.Count 时会得到什么结果?这应该告诉您所有列的计数,无论是否自动生成。
The Count property for the Columns collection in a grid view only counts the number of declared columns you have specified in the markup. When you specify
AutoGenerateColumns="true"
, those columns will not be counted.As an alternative to
GridViewLog.Columns.Count
, what is the result you get when you useGridViewLog.HeaderRow.Cells.Count
? That should tell you the count of all columns, auto generated or not.