Set gridview's column width [duplicate]

≡放荡痞女 提交于 2019-12-12 00:43:52

问题


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.

I wanted to keep it fix.

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.

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.


回答1:


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



来源:https://stackoverflow.com/questions/17881747/set-gridviews-column-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!