mdProgrammer
Programmer
I have an application which was written in .NET 1.1 that used a datagrid that I would dynamically change a cell into a link based on the column and security settings. For example:
Column is an ID field and user has access to the record - Show a link.
Column is an ID field, and user does not have access to the recod - Don't show the link (normal text).
Column is not an ID field - Don't show the link (normal text).
I'm attempting to create a user control for .NET 4.5 (First major project using 4.5, and there's definately a lot of different, and nice features added, so it's a steep learning curve).
I've read that gridviews are the successors to datagrids, and I'm trying to create a usercontrol based on the gridview. Anyway, my problem is that when I change the text to a link in a gridview, it displays the HTML code (the HTML source shows <, &rt;, etc.). I even tried &rt;, < in the code, and it didn't work. However, with the datagrid, links would work just fine. (It's not just links, but any HTML code, like making text bold) Is there a way to make the HTML show up in an individual cell?
I know there are linkcolumns that I can add, but the ID field isn't always known, if it exists at all (as the control is used in multiple webforms).
This is some test code -
Column is an ID field and user has access to the record - Show a link.
Column is an ID field, and user does not have access to the recod - Don't show the link (normal text).
Column is not an ID field - Don't show the link (normal text).
I'm attempting to create a user control for .NET 4.5 (First major project using 4.5, and there's definately a lot of different, and nice features added, so it's a steep learning curve).
I've read that gridviews are the successors to datagrids, and I'm trying to create a usercontrol based on the gridview. Anyway, my problem is that when I change the text to a link in a gridview, it displays the HTML code (the HTML source shows <, &rt;, etc.). I even tried &rt;, < in the code, and it didn't work. However, with the datagrid, links would work just fine. (It's not just links, but any HTML code, like making text bold) Is there a way to make the HTML show up in an individual cell?
I know there are linkcolumns that I can add, but the ID field isn't always known, if it exists at all (as the control is used in multiple webforms).
This is some test code -
Code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="DataGrids.aspx.vb" Inherits="WebApplication1.DataGrids" %>
<!DOCTYPE html>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
<br />
<br />
<strong>DataGrid</strong><asp:datagrid id="dgDataGrid" runat="server">
</asp:datagrid>
<br />
<strong>GridView</strong><asp:GridView ID="gvGridView" runat="server">
</asp:GridView>
</div>
</form>
</body>
</html>
Code:
Public Class DataGrids
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim db As New dbData ' Temporary class name from old application with hideiously non-refactored code. :)
Dim dt As DataTable = db.getDataTable("SELECT 'Test' as 'ID_Column'", db.InventoryConnection)
Dim dv As New DataView(dt)
For i As Integer = 0 To dv.Table.Rows.Count - 1
If dv.Table.Columns(0).ColumnName = "ID_Column" Then
dv.Table.Rows(i).Item(0) = "<a href='[URL unfurl="true"]http://www.google.com'[/URL] target='_blank'>Google</a>"
End If
Next
dgDataGrid.DataSource = dv
gvGridView.DataSource = dv
dgDataGrid.DataBind()
gvGridView.DataBind()
End Sub
End Class