zhshqzyc
asked on
Split long string into many lines in a textbox.
I have an asp.net textbox which stores a long string.
What I did is that
Thanks.
'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'
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>
It doesn't work.Thanks.
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.
On Page Load
this.TextBox1.Text = test.Replace(",", "\r\n");
If you want to go by data binding let me know.
ASKER
The origian question is from a GridView. I want to display a long string. Wrap="true" is not working.
How to modify the code?
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>
Are you getting problem in normal mode or in edit mode
ASKER
Both.
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,
ASKER
Need code.
Alright
Try this :
Try this :
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("test").ToString().Replace(",", Environment.NewLine.ToString()) %>'
TextMode="MultiLine">
</asp:TextBox>
ASKER
It doesn't works. The intellsense doesn't show the methods on EditItemTemplate.
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"
Also just in case, try setting Wrap="true"
ASKER
I 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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.ControlBuild er.Preproc essAttribu te(String filter, String attribname, String attribvalue, Boolean mainDirectiveMode) at System.Web.UI.ControlBuild er.Preproc essAttribu tes(Parsed AttributeC ollection attribs) at System.Web.UI.ControlBuild er.Init(Te mplatePars er parser, ControlBuilder parentBuilder, Type type, String tagName, String id, IDictionary attribs) at System.Web.UI.ControlBuild er.CreateB uilderFrom Type(Templ ateParser parser, ControlBuilder parentBuilder, Type type, String tagName, String id, IDictionary attribs, Int32 line, String sourceFileName) at System.Web.UI.ControlBuild er.CreateC hildBuilde r(String filter, String tagNa... 5823c266-b89d-4c8c-b96b-fc d8dc03acfa
<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>
Line 9
<asp:TextBox ID="TextBox1" runat="server" Wrap="true" TextMode="MultiLine" Text='<%# Bind("ICD9").ToString().Replac
<asp:TextBox ID="TextBox1" runat="server" Wrap="true" TextMode="MultiLine" Text='<%# Bind("ICD9").ToString().Replac e(",", Environment.NewLine.ToStri ng()) %>'>
Bind
should beEval
ASKER
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.
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.
ASKER
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?
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?
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.
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.
ASKER
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>
Please correct my code because of exception.
Rows="'<%# Eval
:(
:(
ASKER
Still wrong.
What exception you are getting?
ASKER
<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>
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)
arrgh.. my bad...
Here it is
Here it is
Rows='<%# Eval("test").ToString().Split(new string[] { "," }, StringSplitOptions.None).Length %>'
ASKER
Many thanks.
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