使用 Linq 数据源的网格视图中自动换行

本文关键字:视图 自动换行 网格 Linq 数据源 使用 | 更新日期: 2023-09-27 17:56:04

我在对网格视图进行自动换行时遇到问题。网格视图的源是在 LinqDataSourceLog_Selecting 方法中构建的 Linq 源。我有一列想要自动换行,但我想由于我绑定 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>

提前感谢您的任何帮助。

使用 Linq 数据源的网格视图中自动换行

网格视图中 Columns 集合的 Count 属性仅计算您在标记中指定的声明列数。 指定 AutoGenerateColumns="true" 时,将不计算这些列。

作为GridViewLog.Columns.Count的替代品,当你使用GridViewLog.HeaderRow.Cells.Count时你会得到什么结果? 这应该告诉您所有列的计数,无论是否自动生成。