DataTable中和GridView换行符 [英] line break in DataTable and GridView

查看:1662
本文介绍了DataTable中和GridView换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我其实想使用C#。我把这个字符串中的DataRow,我加入一个名为确定时代DS。一旦它的完成我这个链接DS确定时代把一个换行符在字符串在asp.net项目到GridView。
这是我的code:

I am actually trying to put a line break in a string in an asp.net project using c#.I put this String in a DataRow that I add to a datable named "ds".Once it's done I link this datable ds to the gridview. This is my code:

            risque.projet = dt.Rows[i]["fk_projet"].ToString();
            risque.release = dt.Rows[i]["fk_release"].ToString();

            //Create the String for adding to the row
            String test = "Project:"+risque.projet+"<br>"+ "Release: "+risque.release;
            drow["Description"] = test;
            Label1.Text = test;


            //Add the row to the datatable.
            ds.Rows.Add(drow);

            //Link the datatable to the gridview
            GridView1.DataSource = ds;
            GridView1.DataBind();

我想这样的输出:

I want this output:

项目:.......

Project:.......

发布:.......

Release:.......

但我一直有:项目:....发布......

but I always have : Project:.... Release......

我试过很多的解决方案:
-System.Environment.NewLine
- \\ r \\ n
- \\ n

I tried many solutions: -System.Environment.NewLine -\r\n -\n

编辑:我gridView.I的code已经没有在我的gridview的,因为所有在运行时创建

Code of my gridView.I have nothing in my gridview because all is created at runtime.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
        EnableSortingAndPagingCallbacks="True" PageSize="5">
        <SelectedRowStyle Wrap="True" />
    </asp:GridView>

但没有任何工程。该br标签工作,但只有当我在标签中显示我的字符串。

But nothing works. The br tag works but only when I display my String in a label.

你有我的错误的想法?你有没有解决方案?我花了太多时间在这。

Do you have an idea of my error?Do you have a solution? I spent too much time on this.

感谢您,

昆汀

推荐答案

它应该放在标签,但该列的HtmlEn code属性设置为false。默认情况下所有字段都是HtmlEn codeD,当然,从像HTML标签停止工作html标签。

It should work put the tag in, but set the column's HtmlEncode property to false. By default all fields are HtmlEncoded, which of course, stops html tags from working like html tags.

不过,如果你这样做,你要htmlen code字段值$ C $手动C-背后prevent XSS。

However, if you're doing this, you'll want to htmlencode the field values manually in code-behind to prevent XSS.

"Project:" + Server.HtmlEncode(risque.projet )+ "<br />" + "Release: " + Server.HtmlEncode(risque.release)

(I preFER的 ANIT-跨站点脚本图书馆HtmlEn code到Server.HtmlEn code的implemmentation,但这是另一个话题。)

(I prefer the Anit-Cross-Site Scripting Library's implemmentation of HtmlEncode to Server.HtmlEncode, but that's another subject.)

这篇关于DataTable中和GridView换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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