Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

GridView / DataGrid difference

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GaryDean - 02 Sep 2007 23:11 GMT
I have a 1.1 control that I wrote that prints a DataGrid as a Crystal Report
and it works just fine.  I now have enhaced it to 2.0 and the ability to
print a GridView.  The gridview, however, doesn't print properly because the
gridview is handling escaped characgters differently.  I placed a
SQLDataSource, a gridview, and a datagrid on a page and bound both grids to
the same datasource pointing to Northwind db.

The gridview shows the escaped characters properly in the web page but they
are not displayed properly in the generated Html (view source).  As you can
see below the snippet from the Gridview shows the name containing
ö.....

<td>BERGS</td><td>Berglunds snabbk&#246;p</td><td>Christina Berglund</td>

The source below is from the datagrid and dispalys the escaped character as
it should be displayed....

<td>BERGS</td><td>Berglunds snabbköp</td><td>Christina Berglund</td>

When my print control digs the data out of the GridView it is getting the
&#246 instead of the O with the two little dots above it.  So it prints it
wrong.  The Gridviw is letting the web page ingterpret the escaped
characters whereas the datagrid apparently does the interpreting before
rendering.

Why this difference?  If I'm going to have to do this conversion myself, is
there any docs on how it's done?
Thanks
Gary

The entire aspx page is pasted here...
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
   <div>
       <table>
           <tr>
               <td style="width: 32px">
               </td>
               <td style="width: 599px">
                   <div style="overflow: auto; width: 869px; height:
244px">
                       <asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="CustomerID"
                           DataSourceID="SqlDataSource1">
                           <Columns>
                               <asp:BoundField DataField="CustomerID"
HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
                               <asp:BoundField DataField="CompanyName"
HeaderText="CompanyName" SortExpression="CompanyName" />
                               <asp:BoundField DataField="ContactName"
HeaderText="ContactName" SortExpression="ContactName" />
                               <asp:BoundField DataField="ContactTitle"
HeaderText="ContactTitle" SortExpression="ContactTitle" />
                               <asp:BoundField DataField="Address"
HeaderText="Address" SortExpression="Address" />
                               <asp:BoundField DataField="City"
HeaderText="City" SortExpression="City" />
                               <asp:BoundField DataField="Region"
HeaderText="Region" SortExpression="Region" />
                               <asp:BoundField DataField="PostalCode"
HeaderText="PostalCode" SortExpression="PostalCode" />
                               <asp:BoundField DataField="Country"
HeaderText="Country" SortExpression="Country" />
                               <asp:BoundField DataField="Phone"
HeaderText="Phone" SortExpression="Phone" />
                               <asp:BoundField DataField="Fax"
HeaderText="Fax" SortExpression="Fax" />
                           </Columns>
                       </asp:GridView>
                   </div>
               </td>
               <td style="width: 126px">
               </td>
           </tr>
           <tr>
               <td style="width: 32px">
               </td>
               <td style="width: 599px">
               </td>
               <td style="width: 126px">
               </td>
           </tr>
           <tr>
               <td style="width: 32px">
               </td>
               <td style="width: 599px">
                   <div style="overflow: auto; width: 869px; height:
244px">
                       <asp:DataGrid ID="DataGrid1" runat="server"
DataSourceID="SqlDataSource1">
                       </asp:DataGrid></div>
               </td>
               <td style="width: 126px">
               </td>
           </tr>

           <tr>
               <td style="width: 32px">
               </td>
               <td style="width: 599px">
               </td>
               <td style="width: 126px">
               </td>
           </tr>
           <tr>
               <td style="width: 32px">
               </td>
               <td style="width: 599px">
                   <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                       SelectCommand="SELECT     CustomerID, CompanyName,
ContactName, ContactTitle, Address, City, Region, PostalCode, Country,
Phone, Fax&#13;&#10;FROM         Customers">
                   </asp:SqlDataSource>
               </td>
               <td style="width: 126px">
               </td>
           </tr>
       </table>
   </div>
   </form>
</body>
</html>
Steven Cheng[MSFT] - 03 Sep 2007 08:36 GMT
Hi Gary,

Regarding on this issue, since the data is retrieved from database and
directly displayed on page through DataGrid or GridView's databound
field(built-in one), I think the problem maybe caused by some particular
processing gridView has peformed.  As far as I know, ASP.NET 2.0 GridView
control has add a "HtmlEncode" attribute, by default it is enabled which
means it will perform HtmlEncoding against the data bound and displayed
through this Field/column. This field is used to protect some malicious
code/script in the text data from executing.

You can try manually disable it as below to see whether it makes the output
become identical to the datagrid ones:

========
 <asp:BoundField  HtmlEncode=false ........../></Columns>
==============

#BoundField.HtmlEncode Property
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfiel
d.htmlencode.aspx

Also, you can use a TemplateField to maually bind and display the column
data through <%# Eval() %> expression to see whether this will suffer the
problem. I assume that using TemplateField and <%# Eval() %> will give the
same output as DataGrid control.

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
   

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "GaryDean" <GaryDean@newsgroups.nospam>
>Subject: GridView / DataGrid difference
[quoted text clipped - 131 lines]
></body>
></html>
GaryDean - 10 Sep 2007 01:26 GMT
The datagrid was converting the escape sequences to characters for my.  The
GridView does not do that - it apparently lets the browser to that.

So, my print utility will have to do the conversions.  Are you aware of any
docs on that process? i.e. converting&#246; to a little o with dots on top?
Thanks,
Gary
Signature

Regards,
Gary Blakely

> Hi Gary,
>
[quoted text clipped - 198 lines]
>></body>
>></html>
Steven Cheng[MSFT] - 11 Sep 2007 03:38 GMT
Thanks for the followup Gary,

Yes, GridView and datagrid have difference on text encoding. So far the
what I get is for built-in BoundColumn or BoundField, GridView has the
"HtmlEncode" attribute setting for you to control the escaping of databound
values while DataGrid didn't(it may always do or not do).

Also, glad that you've found your own way to workaround the problem.

If you have any further questions, please feel free to post here also.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "GaryDean" <GaryDean@newsgroups.nospam>
>References: <Ovimj4a7HHA.4584@TK2MSFTNGP03.phx.gbl>
<qcyH40f7HHA.6140@TK2MSFTNGHUB02.phx.gbl>
>Subject: Re: GridView / DataGrid difference
>Date: Sun, 9 Sep 2007 17:26:23 -0700

>The datagrid was converting the escape sequences to characters for my.  The
>GridView does not do that - it apparently lets the browser to that.
[quoted text clipped - 23 lines]
>>
>> #BoundField.HtmlEncode Property

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfiel
>> d.htmlencode.aspx
>>
[quoted text clipped - 14 lines]
>>
>> Get notification to my posts through email? Please refer to

http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
>> ications.
>>
[quoted text clipped - 158 lines]
>>></body>
>>></html>
GaryDean - 10 Sep 2007 23:14 GMT
turns out it was easy:

HtmlDecode(mystring,writer)
mystring = writer.ToString()

Signature

Regards,
Gary Blakely

> Hi Gary,
>
[quoted text clipped - 198 lines]
>></body>
>></html>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.