[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Split long string into many lines in a textbox.

Posted on 2012-04-10
25
Medium Priority
?
603 Views
Last Modified: 2012-06-27
I have an asp.net textbox which stores a long string.
'99024','99050','99070','99143','99173','99191','99201','99202','99203','99204','99211','99212','99213','99214','99215','99217','99218','99219','99221','99222','99231','99232','99238','99239','99356','99357','99371','99374','99381','99382','99383','99384','99385','99386','99391','99392'

Open in new window

It is a long string without white space. It contains many short strongs that are around single quotes. What I want is to split it into many lines into the textbox. Each line only has one short string.

What I did is that
<asp:TextBox ID="TextBox1" runat="server"  TextMode="MultiLine" Text='<%# Bind("test") %>'>
                                    </asp:TextBox>

Open in new window

It doesn't work.
Thanks.
0
Comment
Question by:zhshqzyc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 10
  • 3
25 Comments
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 37828605
Hi,

Please add Wrap="true" and also add width and height if possible.
<asp:TextBox ID="TextBox1" runat="server"  Wrap="true" TextMode="MultiLine" Text='<%# Bind("test") %>'>

Thanks
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37828613
I tried this from code-behind

On Page Load

this.TextBox1.Text = test.Replace(",", "\r\n");

If you want to go by data binding let me know.
0
 

Author Comment

by:zhshqzyc
ID: 37828642
The origian question is from a GridView. I want to display a long string. Wrap="true" is not working.
How to modify the code?
<asp:TemplateField HeaderText="ICD9" ItemStyle-Width="75px" SortExpression="ICD9">
                            <ItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <%# Eval("ICD9")%>
                                </div>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <asp:TextBox ID="TextBox1" runat="server"  TextMode="MultiLine" Text='<%# Bind("ICD9") %>'>
                                    </asp:TextBox>
                                </div>
                            </EditItemTemplate>
                        </asp:TemplateField>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 37828684
Are you getting problem in normal mode or in edit mode
0
 

Author Comment

by:zhshqzyc
ID: 37828726
Both.
0
 
LVL 16

Expert Comment

by:Imran Javed Zia
ID: 37828747
then you can just insert newline in the string after specific number of charatcers in the source. like insert new line after each 100 or 50 charters in the source string,
0
 

Author Comment

by:zhshqzyc
ID: 37828773
Need code.
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37828882
Alright

Try this :
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("test").ToString().Replace(",", Environment.NewLine.ToString()) %>' 
                                    TextMode="MultiLine">
                                    </asp:TextBox>

Open in new window

0
 

Author Comment

by:zhshqzyc
ID: 37828927
It doesn't works. The intellsense doesn't show the methods on EditItemTemplate.
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37828962
It should work with Edit as well.  Can you take a print screen and post it here.
Also just in case, try setting Wrap="true"
0
 

Author Comment

by:zhshqzyc
ID: 37828993
modeI updated it. Both cases are not working.
 <asp:TemplateField HeaderText="ICD9" ItemStyle-Width="75px" SortExpression="ICD9">
                            <ItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <%# Eval("ICD9").ToString().Replace(",", Environment.NewLine.ToString())%>
                                </div>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <asp:TextBox ID="TextBox1" runat="server" Wrap="true"  TextMode="MultiLine" Text='<%# Bind("ICD9") %>'>
                                    </asp:TextBox>
                                </div>
                            </EditItemTemplate>
                        </asp:TemplateField>

Open in new window

0
 
LVL 27

Accepted Solution

by:
Chinmay Patel earned 2000 total points
ID: 37829044
1.If Intellisense doesn't come for a given code that doesn't mean that code is not valid.

2. I would suggest this update in your code


 <ItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                                                        <asp:TextBox ID="TextBox1" runat="server" Wrap="true"  TextMode="MultiLine" Text='<%# Eval("ICD9").ToString().Replace(",", Environment.NewLine.ToString())%>
' ReadOnly="true">
                                    </asp:TextBox>
                                </div>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <asp:TextBox ID="TextBox1" runat="server" Wrap="true"  TextMode="MultiLine" Text='<%# Eval("ICD9").ToString().Replace(",", Environment.NewLine.ToString())%>
'>
                                    </asp:TextBox>
                                </div>
                            </EditItemTemplate>

Open in new window

0
 

Author Comment

by:zhshqzyc
ID: 37829206
System.Web.HttpException: A call to Bind was not well formatted.  Please refer to documentation for the correct parameters to Bind.    at System.Web.UI.ControlBuilder.PreprocessAttribute(String filter, String attribname, String attribvalue, Boolean mainDirectiveMode)     at System.Web.UI.ControlBuilder.PreprocessAttributes(ParsedAttributeCollection attribs)     at System.Web.UI.ControlBuilder.Init(TemplateParser parser, ControlBuilder parentBuilder, Type type, String tagName, String id, IDictionary attribs)     at System.Web.UI.ControlBuilder.CreateBuilderFromType(TemplateParser parser, ControlBuilder parentBuilder, Type type, String tagName, String id, IDictionary attribs, Int32 line, String sourceFileName)     at System.Web.UI.ControlBuilder.CreateChildBuilder(String filter, String tagNa...      5823c266-b89d-4c8c-b96b-fcd8dc03acfa
<asp:TemplateField HeaderText="ICD9" ItemStyle-Width="75px" SortExpression="ICD9">
                            <ItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <%# Eval("ICD9").ToString().Replace(",", Environment.NewLine.ToString())%>
                                </div>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <asp:TextBox ID="TextBox1" runat="server" Wrap="true"  TextMode="MultiLine" Text='<%# Bind("ICD9").ToString().Replace(",", Environment.NewLine.ToString()) %>'>
                                    </asp:TextBox>
                                </div>
                            </EditItemTemplate>
                        </asp:TemplateField>

Open in new window

0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37829229
Line 9

<asp:TextBox ID="TextBox1" runat="server" Wrap="true"  TextMode="MultiLine" Text='<%# Bind("ICD9").ToString().Replace(",", Environment.NewLine.ToString()) %>'>


Bind

should be

Eval

0
 

Author Comment

by:zhshqzyc
ID: 37829319
Then the error disappears indeed. But it still has same image in normal mode. In edit mode, each row does have one short string. However I have to use arrow to look up the string.
See the image.
test
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37829366
Error must disappear as that's the code I suggested 2 posts back and change your ItemTemplate as well, you are still using old ItemTemplate.
And you have to use arrow 'cause the number of rows you will have is not fixed and it won't do any good t have a very large textarea.

If you must provide the full view then we can increase the rows of textarea. Just bind its Rows property as I have done with Text property.
0
 

Author Comment

by:zhshqzyc
ID: 37829468
It is almost there. Two questions.
1. If I use asp.net label instead of textbox, is it possible to wrap the text in normal mode?
2. How to increase the rows of textarea?
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37829568
1. Depends on many factors basically the style we attach and the style of parent container.
2. Bind its rows properties to
("ICD9").Split(',').Length

Also dont just copy the code, try to understand the trick behind it. Try to understand the trick and you would'nt have to hunt for the code.
0
 

Author Comment

by:zhshqzyc
ID: 37829641
Awesome,
 
<asp:TextBox ID="TextBox1" runat="server" Wrap="true" TextMode="MultiLine" Text='<%# Eval("ICD9").ToString().Replace(",", Environment.NewLine.ToString())%>'
                                        Rows="'<% Eval("ICD9").ToString().Split(',').Length %>'" ReadOnly="true">
                                    </asp:TextBox>

Open in new window

Please correct my code because of exception.
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37829665
Rows="'<%# Eval
:(
0
 

Author Comment

by:zhshqzyc
ID: 37829691
Still wrong.
0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37829700
What exception you are getting?
0
 

Author Comment

by:zhshqzyc
ID: 37829752
<ItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <asp:TextBox ID="TextBox1" runat="server" Wrap="true" TextMode="MultiLine" Text='<%# Eval("ICD9").ToString().Replace(",", Environment.NewLine.ToString())%>'
                                        Rows="'<%# Eval("ICD9").ToString().Split(',').Length %>'" ReadOnly="true">
                                    </asp:TextBox>
                                </div>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <div style="width: 75px; overflow: hidden; white-space: nowrap; word-wrap: break-word;">
                                    <asp:TextBox ID="TextBox2" runat="server" Wrap="true" TextMode="MultiLine" Text='<%# Eval("ICD9").ToString().Replace(",", Environment.NewLine.ToString())%>
'>
                                    </asp:TextBox>
                                </div>
                            </EditItemTemplate>

Open in new window

The exception is
ystem.Web.HttpException: The server tag is not well formed.    at System.Web.UI.TemplateParser.ProcessError(String message)     at System.Web.UI.TemplateParser.ParseStringInternal(String text, Encoding fileEncoding)

Open in new window

0
 
LVL 27

Expert Comment

by:Chinmay Patel
ID: 37829835
arrgh.. my bad...

Here it is
Rows='<%# Eval("test").ToString().Split(new string[] { "," }, StringSplitOptions.None).Length %>'

Open in new window

0
 

Author Closing Comment

by:zhshqzyc
ID: 37829853
Many thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question