Displaying XML data as is with tags on the datagrid

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"))
%>
 
M

MSFT

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.)
 
M

Mark Schubert

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;

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top