ASP.NET - grid - Asked By msakt on 08-May-12 06:56 AM

s<asp:TemplateField HeaderText="Address1" HeaderStyle-HorizontalAlign="Left">
                      <EditItemTemplate>
                        <asp:TextBox ID="txtAddress1" runat="server" Text='<%# Eval("Address1") %>' Width="90px"></asp:TextBox>
                      </EditItemTemplate>
                      <ItemTemplate>
                        <asp:Label ID="lblAddress1" runat="server" Text='<%# Eval("Address1") %>' Width="90px"></asp:Label>
                      </ItemTemplate>
                      <ItemStyle Wrap="True" />
                      <HeaderStyle Wrap="True" Width="90px"  />
                    </asp:TemplateField>
in gridview,if address1 value have long value..its merge in next column...so i want new line in same column like this
2 mm street
mmmmm
S K replied to msakt on 08-May-12 07:16 AM
You can use wrod wrap true with the width in that column within gridview as follows

<ItemStyle Wrap="true" Width="100px" />



Chintan Vaghela replied to msakt on 08-May-12 07:34 AM

Hello,

 

Set ItemStyle Width

 

  <asp:TemplateField HeaderText="Address1" HeaderStyle-HorizontalAlign="Left">

          <EditItemTemplate>

            <asp:TextBox ID="txtAddress1" runat="server" Text='<%# Eval("DrpValue") %>' Width="90px"></asp:TextBox>

          </EditItemTemplate>

          <ItemTemplate>

            <asp:Label ID="lblAddress1" runat="server" Text='<%# Eval("DrpValue") %>' Width="90px"></asp:Label>

          </ItemTemplate>

          <ItemStyle  Width="90px" />

 

          <HeaderStyle Width="90px" />

        </asp:TemplateField>

 

 

 

Hope this helpful!

Thanks

 

 

 

msakt replied to Chintan Vaghela on 08-May-12 07:45 AM
in this method..  if value is like this  anaheimTrainms  not work
but if value is like this anaheim Trainms its work
Chintan Vaghela replied to msakt on 08-May-12 08:36 AM

Hello,

 

Use following BreakLong String function and call this function as following way

 

<asp:TemplateField HeaderText="Address1" HeaderStyle-HorizontalAlign="Left">

          <EditItemTemplate>

            <asp:TextBox ID="txtAddress1" runat="server" Text='<%# Eval("DrpValue") %>' Width="90px"></asp:TextBox>

          </EditItemTemplate>

          <ItemTemplate>

            <asp:Label ID="lblAddress1" runat="server" Text='<%# BreakLongString(Eval("DrpValue").ToString(),10) %>' Width="90px"></asp:Label>

          </ItemTemplate>

          <ItemStyle  Width="90px" />

          <HeaderStyle Width="90px" />

         

        </asp:TemplateField>

 

 

 

public string BreakLongString(string SubjectString, int CharsToBreakAfter)

    {

      string Pattern = "\\S{" + CharsToBreakAfter + ",}";

      int Counter = 0;

      bool IsMatching = Regex.IsMatch(SubjectString, Pattern);

      while (IsMatching)

      {

 

        Counter++;

        string MatchedString = Regex.Match(SubjectString, Pattern).Value;

        SubjectString = SubjectString.Replace(MatchedString.Substring(0, (CharsToBreakAfter - 1)), MatchedString.Substring(0, (CharsToBreakAfter - 1)) + " ");

 

        // Prevent endless loops

        if (Counter > 20) break;

 

        // Check if we still have long strings

        IsMatching = Regex.IsMatch(SubjectString, Pattern);

      }

 

      return SubjectString;

    }

 

Hope this helpful!

Thanks

 

 

 

dipa ahuja replied to msakt on 09-May-12 07:42 AM
<div style="word-wrap: break-word; width: 250px;">
<%--<controls>--%>
<asp:Literal ID="Literal1" Text='<%# Bind("Name") %>' runat="server"></asp:Literal>
</div>