Reputation: 25
In process to integrate my Console based application to Web based application, I came across the following problem:
I need to display data in a Multiline Text Box (as per requirement) such that each record is displayed in the text box without overwriting the previous(it should be in the next line).
For Windows Forms I was using the following code:
if (reader.HasRows)
{
while (reader.Read())
{
predicted_grade = reader["Domain"].ToString();
priority = "Priority: " + i;
predicted_grade = priority +" --- "+predicted_grade + "\r\n";
textBox2.AppendText(predicted_grade);
i++;
}
}
But since AppendText property does not run in ASP.net Website, I don't Know how to do it. Please guide me, that how I should make the data appear as:
Code | Course Name | Predicted_Grade
1 | Science | A+
2 | Maths | B
3 | History | C
using Multi line text box
Upvotes: 1
Views: 1851
Reputation: 2149
You can do the AppendText functionality in ASP.NET pages by modifying your
predicted_grade = priority +" --- "+predicted_grade + "\r\n";
textBox2.AppendText(predicted_grade);
to
predicted_grade = priority +" --- "+predicted_grade + Environment.NewLine;
textBox2.Text += predicted_grade;
Or if you use AppendText()
in many pages in your project, you can create an extension method AppendText
to TextBox control:
public static class MyExtensions
{
public static void AppendText(this TextBox textBox, String text)
{
textBox.Text += text;
}
}
To use it, just call:
predicted_grade = priority +" --- "+predicted_grade + Environment.NewLine;
textBox2.AppendText(predicted_grade);
You can also use the extension method to take care of the \r\n
for you:
public static void AppendLine(this TextBox textBox, String text)
{
textBox.Text += text + Environment.NewLine;
}
To use it, just call:
predicted_grade = priority +" --- "+predicted_grade;
textBox2.AppendLine(predicted_grade);
P/S: \r\n
won't work in ASP.Net TextBox, so you need to use NewLine as mentioned by Darren
Upvotes: 1
Reputation: 70728
You can use Environment.NewLine
:
textBox2.Text = predicted_grade + Environment.NewLine;
http://msdn.microsoft.com/en-GB/library/system.environment.newline.aspx
Upvotes: 1