Link在一个DataRow(数据表)

编程入门 行业动态 更新时间:2024-10-25 04:16:22
本文介绍了Link在一个DataRow(数据表)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我动态生成一个DataTable,我尝试添加在我加入到DataTable DataRow中(S)链接。该数据表绑定到一个GridView之后的创作

I'm building a DataTable dynamically and I'm trying to add a "link" in the DataRow(s) that I'm adding to the DataTable. The DataTable is bound to a GridView after it's creation.

类似的东西:

DataTable dataTable = new DataTable(); foreach (Item item in items) { DataRow row = dataTable.NewRow(); dataTable.Columns.Add(new DataColumn("col")); row["col"] = "<a href='www.google'>Link here</a>"; dataTable.Rows.Add(row); }

然后我把它绑定到一个GridView:

Then I bind it to a GridView :

<asp:GridView ID="grdView" Runat="server" border="0" EnableViewState="true" style="width:100%;" AutoGenerateColumns="true" AllowPaging="false" PagerSettings-Visible="false" ShowHeader="true" ShowFooter="true" CellPadding="0" CellSpacing="0" Visible="True"> </asp:GridView>

但是,当我把它绑定到GridView在列中的HTML编码。 是有办法有添加一个超链接的对象或成这样?

But the HTML in the Column is encoded when I bind it to the GridView. Is there a way to add a HyperLink object there or something like that?

P.S东西。这不是在本例中,但列的动态添加(这意味着我不渲染我多少列必须知道之前)

P.S. It's not in the example but the columns are added dynamically (it means that I don't know before the rendering how many columns I'll have)

更新#1

我有机会到GridView当我创建的列。 我能够做这样的事情:

I have access to the GridView when I create the columns. I was able to do something like that :

dataTable.Columns.Add(new DataColumn("col")); BoundField bf = new BoundField(); bf.HtmlEncode = false; bf.DataField = "col"; grd.Columns.Add(bf); row["col"] = "<a href='www.google'>Link here</a>";

但它显示2 coloumns山坳...

But it displays 2 coloumns "col"...

更新3: 我用一个DataGrid来代替。在数据行纯文本插入时它不编码的HTML。

UPDATE #3 : I used a DataGrid instead. It doesn't encode HTML when inserted in "plain text" in the data rows.

推荐答案

它是一个长久以来这段时间有人问,但我来到这里是第一个谷歌搜索结果中的一个,所以我想告诉你,我已经解决了这个加入了HyperLinkField字段:

It's been an long time since this was asked, but I arrived here being one of the first google results, so I would like to tell you that I have resolved this adding a "HyperLinkField":

HyperLinkField myLink = new HyperLinkField(); myLink.HeaderText = "Link Here"; myLink.DataTextField = "Click here"; myLink.DataNavigateUrlFields = new string[] { "field1", "field2", "field3" }; myLink.DataNavigateUrlFormatString = "NewPage.aspx?id={0}&otherId={1}&otherId2={2}"; myGridView.Columns.Add(myLink); //Finally bind the data... myGridView.DataBind();

更多推荐

Link在一个DataRow(数据表)

本文发布于:2023-10-16 10:33:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497319.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据表   Link   DataRow

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!