日期:2014-05-18  浏览次数:20839 次

这段代码中为什么ltrhist.Text后用+=而不用=?
C# code
        private void Hist(crd_query_msg credit)
        {
                       var hists = credit.crd_hist;
            var format = "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td></tr>";

            int i = 0;
            foreach (var hist in hists)
            {
                i++;
                ltrhist.Text += string.Format(format, i, hist.QRY_DATE.NullToString(), hist.APPT_NAME, hist.CAUSE ?? "未知",
                hist.INFO_TYPE, hist.QRY_MODE, hist.TIME_STAMP.NullToString());
            }
        }

ltrhist是个literal控件

------解决方案--------------------
C# code

ltrhist.Text += string.Format(format, i, hist.QRY_DATE.NullToString(), hist.APPT_NAME, hist.CAUSE ?? "未知",
                hist.INFO_TYPE, hist.QRY_MODE, hist.TIME_STAMP.NullToString());
等同于
ltrhist.Text =ltrhist.Text + string.Format(format, i, hist.QRY_DATE.NullToString(), hist.APPT_NAME, hist.CAUSE ?? "未知",
                hist.INFO_TYPE, hist.QRY_MODE, hist.TIME_STAMP.NullToString());

------解决方案--------------------
ltrhist.Text += "aaa" 意思就是
ltrhist.Text = ltrhist.Text + "aaa"
------解决方案--------------------
这是追加文本,
将hists里的所有文本都追加到ltrhist.Text