【问题标题】:Word Wrap in Gridviews with Linq DataSource使用 Linq 数据源在 Gridviews 中自动换行
【发布时间】:2011-05-10 15:12:36
【问题描述】:

我遇到了 Gridview 自动换行的问题。 Gridview 的源是在 LinqDataSourceLog_Selecting 方法中构建的 Linq 源。我有一列我想自动换行,但我想由于我绑定 Gridview 的方式,列数始终为 0,所以我无法换行我没有的东西。以下是 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>

提前感谢您的帮助。

【问题讨论】:

    标签: c# asp.net visual-studio linq gridview


    【解决方案1】:

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

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

    【讨论】:

    • 非常好。我得到了正确的列数,但是我仍然无法包装该列。我试过 GridViewLog.HeaderRow.Cells[6].Wrap = true;但无济于事。
    猜你喜欢
    • 2011-08-29
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-29
    相关资源
    最近更新 更多