vb.net 设置gridview的列宽

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17881747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 14:25:17  来源:igfitidea点击:

Set gridview's column width

c#asp.net.netvb.netvisual-studio-2008

提问by C Sharper

I have gridview as follows:

我有 gridview 如下:

enter image description here

在此处输入图片说明

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

但是当我输入任何更大的文本时,它的列会增加如下:

enter image description here

在此处输入图片说明

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

在这里我们可以看到,当我输入大文本英文问题列的 with 已经生效。

I wanted to keep it fix.

我想把它修好。

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

为此,我<ItemStyle HorizontalAlign="Left" Width="45%" />在网格的模板字段中添加 了

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

但它不工作。我也是wrap="true"为标签制作的。但对结果没有影响。

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>

Please help me.

请帮我。

回答by Aaron

Try to set the RowStyle-Wrapproperty of the gridviewto True.

尝试将 的RowStyle-Wrap属性设置gridview为 True。