设置GridView的列宽

设置GridView的列宽

本文介绍了设置GridView的列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的GridView如下:

I have gridview as follows:

但是,当我进入与它的文本任何较大,其与被增加为列如下:

But when i enters any larger with text in it, its column with gets increased as follows:

在此,我们可以看到,当我已经进入大的文本英语提问柱与已经得到了实现。

In this we can see that when i have entered large text English Question column's with has got effected.

我想保持其固定。

有关我添加< ItemStyle Horizo​​ntalAlign =左WIDTH =45%/> 在网格模板列

For that i added <ItemStyle HorizontalAlign="Left" Width="45%" /> in grid's templatefield

但它不工作。我还做了包装=真正的的标签。但结果没有影响。

but its not working. I also made wrap="true" for label. but no effect on result.

为了更清楚我的整个code电网如下:

For more clarity my whole code for grid is as follows:

  <asp:GridView ID="GrdQuestions" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                        CssClass="NormalText" PageSize="100" Width="100%">
                        <HeaderStyle CssClass="TableHeadingNormal TableAlt2" HorizontalAlign="Center" />
                        <RowStyle CssClass="AltColor21" />
                        <AlternatingRowStyle CssClass="AltColor22" />
                        <Columns>
                            <asp:TemplateField HeaderText="SrNo" HeaderStyle-HorizontalAlign="Center">
                                <ItemTemplate>
                                    <asp:Label ID="lblID" runat="server" Text='<%# Bind("SrNo") %>'></asp:Label>
                                    <asp:Label ID="lblQMID" runat="server" Text='<%# Bind("QMId") %>' Visible="false"></asp:Label>
                                </ItemTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                                <ItemStyle HorizontalAlign="Center" Width="3%" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="English Question">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtEnglish" runat="server" Text='<%# Bind("English") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblEnglish" runat="server" Text='<%# Bind("English") %>'></asp:Label>
                                    <%--
                                   <%# Eval("English") %>--%>
                                </ItemTemplate>
                                <HeaderStyle />
                                <ItemStyle HorizontalAlign="Left" Width="45%" Wrap="true" />
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Spanish Question">
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtSpanish" runat="server" Text='<%# Bind("Spanish") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblSpanish" runat="server" Text='<%# Bind("Spanish") %>'></asp:Label>
                                    <%-- <%#Eval("Spanish")%>--%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Left" Width="45%" Wrap="true" />
                            </asp:TemplateField>
                            <asp:TemplateField ShowHeader="False" HeaderStyle-HorizontalAlign="Center">
                                <EditItemTemplate>
                                    <asp:LinkButton ID="LBUpdate" runat="server" CausesValidation="True" CommandName="Update"
                                        Text="Update"></asp:LinkButton>
                                    &nbsp;<asp:LinkButton ID="LBCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text="Cancel"></asp:LinkButton>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:LinkButton ID="LBEdit" runat="server" CausesValidation="False" CommandName="Edit"
                                        Text="Edit"></asp:LinkButton>
                                    <asp:LinkButton ID="LinkButton4" runat="server" CausesValidation="False" CommandArgument='<%# Bind("SrNo") %>'
                                        CommandName="Delete" Text="Delete"></asp:LinkButton>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                                <HeaderStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>

请帮我。

推荐答案

尝试设置 RowStyle换行 GridView控件的属性为True。

Try to set the RowStyle-Wrap property of the gridview to True.

这篇关于设置GridView的列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:56