Eric
Eric

Reputation: 8088

Word Wrap in Gridviews with Linq DataSource

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.

Upvotes: 0

Views: 389

Answers (1)

CheckRaise
CheckRaise

Reputation: 550

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.

Upvotes: 2

Related Questions