如何使用c#,net在textarea中动态添加文本? [英] how to add text in textarea dynamically using c#,net?

查看:349
本文介绍了如何使用c#,net在textarea中动态添加文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string query = String.Empty;
        query = "SELECT messages FROM comments";
        OdbcConnection con = new OdbcConnection(str);
        con.Open();
        OdbcCommand cmd = new OdbcCommand(query, con);
        OdbcDataAdapter adap = new OdbcDataAdapter(cmd);
        DataSet ds = new DataSet();
        adap.Fill(ds, "results");
        //String temp_msg = "";
        foreach (DataRow row in ds.Tables["results"].Rows)
        {
             this.comments.Value += row["messages"].ToString();
            
            this.comments.Value = Environment.NewLine;
        }



上面是我用来在textarea中显示消息的代码..但是它没有显示任何内容..但是值正在检索..我们还有其他想法吗..pls让我知道.. 因为它非常紧急 ..真的需要您的帮助..

谢谢
问候
velu



the above is the code i am using for showing the messages in textarea ..but it s not showing anything..but the values are retrieiving..do we have any other idea..pls let me know..since its very urgent..looking for ur help really..

thanks
regards
velu

推荐答案

this.comments.Value += row["messages"].ToString();

this.comments.Value = Environment.NewLine;

也许第二行也是 也是 "+ =而不是" =会有所不同吗?

顺便说一句:用StringBuilder替换this.comments.Value是很有意义的-特别是在预计会有很多行的情况下-请记住,字符串在C#中是不可变的,因此每次将两个字符串中的两个连接在一起时就创建一个新字符串他们.

Perhaps if the second line was also "+=" rather than "=" it would make a difference?

BTW: it would make a lot of sense to replace the this.comments.Value with a StringBuilder - particularly if there are expected to be a lot of rows - remember that strings are immutable in C# so you create a new string every time you concatenate two of them.


这篇关于如何使用c#,net在textarea中动态添加文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆