473,387 Members | 1,669 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGrid Mystery

I have a situation where characters are somehow getting stripped from a
textbox in an ItemTemplate in a cell of a DataGrid.

In the itemDataBound event I am moving data from columns created at run time
into other columns, created at design time, I have set up with Textboxes.
This program has ran correctly for months until this recent condition.

I have come upon the situation where a nvarchar field in a SQLServer table
has a carriage return character in it - a hex 0D. After the following two
lines of code are executed in the ItemDataBound event.....

Dim mytb As TextBox = CType(e.Item.Cells(t + 1).Controls(1), TextBox)
mytb.Text = e.Item.Cells(t + dg.Columns.Count).Text

mytb.Text correctly has received the string complete with the "0D" character
intact. However, when the grid is diplayed and later posted back, the "0D"
character is gone from the string. My program then makes an incorrect
assumption that the user modified the value in the textbox.

How and why is this 0D character getting stripped from the textbox?

--
Regards,
Gary Blakely
Sep 8 '06 #1
3 1572
Hi Gary,

For multiline text content, I think you need to use a textarea (set
TextMode="Multiline") instead of a simple input.

You can verify this behavior by using following simple WebForm:

<form id="form1" runat="server">
<div>
<asp:TextBox ID="text1" runat="server"></asp:TextBox>
<asp:textbox ID="text2" runat="server"
TextMode="multiLine"></asp:textbox>
<asp:button id="button1" runat="server" text="button1"
OnClick="button1_Click"></asp:button>
<asp:Button ID="button2" runat="server" Text="button2"
OnClick="button2_Click" />
</div>
</form>

Code-behind:

protected void button1_Click(object sender, EventArgs e)
{
text1.Text = "hello\rworld";
text2.Text = "hello\rworld";
}
protected void button2_Click(object sender, EventArgs e)
{
Response.Write("Carriage Return in text1: " +
text1.Text.IndexOf('\r') + "<br>");
Response.Write("Carriage Return in text2: " +
text2.Text.IndexOf('\r') + "<br>");
}

Text2 retains the Carriage Return because its TextMode set to "Multiline".

I hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 11 '06 #2
Walter,
Yes. That solves my "mystery." It is stripping carriage returns and line
feeds probably. I wonder if it strips anything else.

-
Regards,
Gary Blakely
"Walter Wang [MSFT]" <wa****@online.microsoft.comwrote in message
news:dZ****************@TK2MSFTNGXA01.phx.gbl...
Hi Gary,

For multiline text content, I think you need to use a textarea (set
TextMode="Multiline") instead of a simple input.

You can verify this behavior by using following simple WebForm:

<form id="form1" runat="server">
<div>
<asp:TextBox ID="text1" runat="server"></asp:TextBox>
<asp:textbox ID="text2" runat="server"
TextMode="multiLine"></asp:textbox>
<asp:button id="button1" runat="server" text="button1"
OnClick="button1_Click"></asp:button>
<asp:Button ID="button2" runat="server" Text="button2"
OnClick="button2_Click" />
</div>
</form>

Code-behind:

protected void button1_Click(object sender, EventArgs e)
{
text1.Text = "hello\rworld";
text2.Text = "hello\rworld";
}
protected void button2_Click(object sender, EventArgs e)
{
Response.Write("Carriage Return in text1: " +
text1.Text.IndexOf('\r') + "<br>");
Response.Write("Carriage Return in text2: " +
text2.Text.IndexOf('\r') + "<br>");
}

Text2 retains the Carriage Return because its TextMode set to "Multiline".

I hope this helps. Please feel free to post here if anything is unclear.

Sincerely,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your
reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Sep 11 '06 #3
Gary,

So far I've tested that \r and \n get striped, \t works ok. I think any
other non-print characters will also be striped. This issue is not ASP.NET
related, it's by design behavior of html form input fields.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 12 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Chumley the Walrus | last post by:
Even tho all my field names are named right, I cannot figure why I am getting a "Specified argument was out of the range of valid values. Parameter name: index" error on the line that holds " Dim...
5
by: Jeff Cook | last post by:
Hi I have a DataGrid that I am using to display a .xml file (that has a schema in a .xsd), like this:- ds.ReadXmlSchema(sDataPath + "Data.xsd"); ds.ReadXml(sDataPath + "Data.xml",...
5
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within...
0
by: Robert Brinson | last post by:
Hello all! I'm running .NET Framework 1.1 using VS.NET 2003. I've got a mystery with a DataGrid. Below is the definition of the DataGrid from my aspx page: </asp:datagrid><asp:datagrid...
0
by: Jim Hammond | last post by:
The code below implements two datagrid columns that display images. The first column is just a test that always displays the same image directly from a file. The second column pulls the image from...
8
by: Sue | last post by:
I have a datagrid populated with 6 visible read-only labels and several hidden fields. Below the datagrid, I have a table with various textboxes, dropdowns, etc. I've managed to decypher the...
1
by: Leo | last post by:
Can someone tell me how to make the sorting triangle on datagrid column header always show up? And which property can change the color of the triangle ? The default color is white. Thanks
14
by: jojoba | last post by:
Hi, I hope this post is ok for this group. Here's my deal: I have two computers on my LAN at home. One desktop. One laptop. Both computers are wireless enabled (and wired enabled too). I...
2
by: gsb58 | last post by:
Hi! I'm using Visual Studio .NET 2003 (using C#). On a form I have a datagrid where I've set the DataSource and DataMember to receive values from a view in a SQL 2000 database. It works fine....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.