Displaying XML data as is with tags on the datagrid

  • Thread starter Thread starter Nedu N
  • Start date Start date
N

Nedu N

Hi,

I want to display the XML tags (for the the XML tags is the data that is
stored in a table) on the datagrid using the datasets. But since the data
itself is the XML tag it doesn't appera on the datagrid since it tries to
parse the data before it displays.

Using Server.HtmlEncode, i was able to display the right content on the
datagrid for each and every colum using Template column. But i don't want to
use any template columns since i have got all the columns are having the
data as XML tags as is and i have many cloumns.

So, is there anyway i can directly achieve this while binding the datagrid
with the dataset without using Template columns for each of the coulmns?
Using Server.HtmlEncode, I was able to handle each column like
<%#
Server.HtmlEncode((string)DataBinder.Eval(Container.DataItem,"TableColumn"))
%>
 
Please refer to my reply in
microsoft.public.dotnet.framework.aspnet.webcontrols. Thanks.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Try performing the encoding in the ItemDataBound Event as follows:

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{

switch(e.Item.ItemType)

{

case ListItemType.Item:

// THIS ENCODES ANY TEXT GOING INTO CELLS SO THAT THERE IS NO CHANCE OF
SCRIPT INJECTION

foreach (Control c in e.Item.Controls)

{

TableCell cell = (TableCell) c;

string text = cell.Text;

if (text != " " && text != "")

{

if (text == "&nbsp;") text = "";

cell.Text = HttpUtility.HtmlEncode(text);

}

}

break;

}

}
 
Back
Top