0

I have gridview as follows:

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.

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.

C Sharper
  • 8,284
  • 26
  • 88
  • 151
  • @butterbox i tried that things,,i already mentioned it in my question. – C Sharper Jul 26 '13 at 12:56
  • have you checked http://stackoverflow.com/questions/10980365/set-gridview-column-width-programatically-in-asp-net to? – butterbox Jul 26 '13 at 12:58
  • @butterbox that is giving me error – C Sharper Jul 26 '13 at 13:05
  • Have you tried templating them with a textblock and setting the wrap property on the text block? – Bearcat9425 Jul 26 '13 at 13:13
  • @Bearcat9425 I done it with label wrap="true" – C Sharper Jul 26 '13 at 13:15
  • Only thing I have read is wrapping that column in a div and applying css to it like so,
    <%#Eval("DisplayOnIssueSummary") %>
    I also read in a few places that there is a bug with wrap cause its not valid html. See here http://social.msdn.microsoft.com/Forums/vstudio/en-US/49d3ecf2-688e-4a4c-99c2-5feb39ed8871/gridview-text-not-wrapping-in-ie8
    – Bearcat9425 Jul 26 '13 at 13:44

1 Answers1

4

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

C Sharper
  • 8,284
  • 26
  • 88
  • 151
Aaron
  • 1,361
  • 1
  • 13
  • 30