使用 Linq DataSource 在 Gridview 中自动换行

发布于 2024-11-06 05:27:31 字数 2332 浏览 0 评论 0原文

我在对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撧情箌佬 2024-11-13 05:27:31

网格视图中 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 use GridViewLog.HeaderRow.Cells.Count? That should tell you the count of all columns, auto generated or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文