如何在转发器中绑定多行文本

如何在转发器中绑定多行文本

本文介绍了如何在转发器中绑定多行文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在转发器中绑定来自后端的多行文本..

i已经使用过这个..

Text ='<%#Limit( Eval(feedback_details),40)%>'





aspx.cs文件...

I need to bind multiple lines of text from backend in repeater..
i have used this..
Text='<%#Limit(Eval("feedback_details"),40)%>'


aspx.cs file...

protected string Limit(object Desc, int length)
    {
    StringBuilder strDesc = new StringBuilder();
    strDesc.Insert(0, Desc.ToString());

    if (strDesc.Length > length)
    {
        return strDesc.ToString().Substring(0, length) + "...";
    }
    else return strDesc.ToString();
    }





它在同一行显示文字

这是一个样本.......



i想要这样实现

这是一个示例段落。

这是一个示例段落。

这是一个....




请帮助我..



it displays the text in same line like this
this is a sample.......

i want to implement like this
this is a sample paragraph.
this is a sample paragraph.
this is a....


kindly help me..

推荐答案

I have considered 'Desc' as string input




string Desc = "Hell\r\noWorld\r\nHow\r\nAre\r\n";
        protected string Limit(int length)
        {
            string strDesc = Convert.ToString(Desc);
            string[] lines = Regex.Split(strDesc, Environment.NewLine);
            string s = "";
            int TotalLength = 0;
            int cnt = 0;
            //Finding total length of all strings
            for (int i = 0; i < lines.Length; i++)
            {
                TotalLength += lines[i].Length;
            }
            if (TotalLength > length)
            {
                //Making of String with "<br/>
                s = lines[0];
                length = length - lines[0].Length;
                cnt = 1;
                while (length > 0)
                {
                    if (lines[cnt].Length < length)
                    {
                        s += "<br/>" + lines[cnt];
                        length = length - lines[cnt].Length;
                    }
                    else
                    {
                        s += "<br/>" + lines[cnt].Substring(0, length);
                        length = 0;
                    }
                    cnt++;
                }
                return s + "...";
            }
            else
            {
                return strDesc.Replace(Environment.NewLine, "<br/>");
            }

        }


这篇关于如何在转发器中绑定多行文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 09:07