简体   繁体   English

需要在多行文本框中显示来自SQL的数据

[英]Need to Display Data From SQL in a Multiline TextBox

In process to integrate my Console based application to Web based application, I came across the following problem: 在将基于控制台的应用程序集成到基于Web的应用程序的过程中,遇到了以下问题:

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: 对于Windows窗体,我使用以下代码:

        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. 但是由于AppendText属性不能在ASP.net网站中运行,所以我不知道该怎么做。 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 使用多行文本框

You can use Environment.NewLine : 您可以使用Environment.NewLine

textBox2.Text = predicted_grade + Environment.NewLine;

http://msdn.microsoft.com/en-GB/library/system.environment.newline.aspx http://msdn.microsoft.com/en-GB/library/system.environment.newline.aspx

You can do the AppendText functionality in ASP.NET pages by modifying your 您可以通过修改您的ASP.NET页中的AppendText功能

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: 或者,如果您在项目的许多页面中使用AppendText() ,则可AppendText TextBox控件创建扩展方法AppendText

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: 您还可以使用扩展方法来为您处理\\r\\n

    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 P / S: \\r\\n在ASP.Net TextBox中不起作用,因此您需要使用Darren提到的NewLine

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM