Render <instead of <in ASP.NET

I am writing a small page to show the employees in our company. I wrote a request to pull information from our database. Then I bind to the GridView to do the dirty work. Here is the request.

"SELECT tblEmpID.empid AS [Empl ID], tblEmpID.posno AS [Pos #], [name] & ""<br />""  &   [jcn] & ""("" & [jcc] & "")"" AS [Name/Job], [orgno] & "" - "" & [depname] AS Department, tblEmpID.[status] AS Status " & _
        "FROM tblEmpID " & _
        "ORDER BY [orgno] & "" - "" & [depname], tblEmpID.name "

      

As you can see, I am trying to include
inside the SQL, so when it displays it it looks like this:

Name
Job Description

      

But when it displays it, it displays as

&lt; and &gt;

      

Effectively showing in the recording instead of formatting as I want.

So how do I render the way I want? I've already tried running away from <c \ and it didn't work.


EDIT: Thanks gfrizzle. Your answer put me on the right track. Also, thanks to NYSystemsAnalyst. Your answer helped me think of another way to do things in the future. Ultimately, I found another solution. I put this code in the GridView1_RowDataBound event and it does what I need.

If e.Row.RowType = DataControlRowType.DataRow Then
        Dim cells As TableCellCollection = e.Row.Cells

        For Each cell As TableCell In cells
            cell.Text = Server.HtmlDecode(cell.Text)
        Next
    End If

      

0


source share


2 answers


Try setting HtmlEncode = "False" on a column in the GridView. This should stop it from coding your markup.



+1


source


If you are doing this read-only, you might want to consider using a relay control. Then you can return them as separate fields, thus excluding HTML from the SQL result set. Then you can use the ItemTemplate on the control to specify the HTML and exactly how you want the results to appear. You can place them in a table and use the BR tag. It will look like a grid, but give you more control over the layout on the HTML / .aspx side.



0


source







All Articles