My item template in gridview is marked up like this.
Where do I add the tags?
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<% Eval("datacol") %>'
</asp:Label>
</ItemTemplate>
My item template in gridview is marked up like this.
Where do I add the tags?
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<% Eval("datacol") %>'
</asp:Label>
</ItemTemplate>
Since I realize this is related to your previous question: http://stackoverflow.com/questions/924058/asp-net-binding-to-gridview-strips-some-space-whitespace-characters/924115#924115
Please refer to my answer in that question. The same principle could be used to add any type of tags around your DataBound values. For this specific question, an approach like this could accomplish what you want.
protected void gbGridWithSpaces_RowDataBound(object sender, GridViewRowEventArgs e)
{
foreach (TableCell cell in e.Row.Cells)
{
cell.Text = "<pre>" + cell.Text + "</pre>";
}
}
Another alternative is to create your own custom control and place there
<ItemTemplate>
<cc1:MyCustomControl ID="MyCustomControl1" runat="server" Text='<% Eval("datacol") %>' />
</ItemTemplate>
Really, I don't know if it's better, maybe is a little expensive create a class/user control only for adding pre tags, but I think is less obstrusive at your code-behind file.
Am I missing something?
Why not try:
<ItemTemplate>
<pre><%# Eval("datacol") %></pre>
</ItemTemplate>
It keeps the HTML in the ASPX page where it generally belongs, unless you specifically need the label tag.