Home All Groups Group Topic Archive Search About

Why doesn't work DataFormatString for GridView.BoundField ?

Author
23 Jan 2007 7:56 PM
Pavel
I have this code below and no format I put in property DataFormatString
works. Why is it so?

<%@ 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>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False"
            DataKeyNames="ID" DataSourceID="SqlDataSource1">
            <PagerSettings Mode="NumericFirstLast" />
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True"
                    SortExpression="ID" >
                    <ItemStyle Width="100px" />
                </asp:BoundField>
                <asp:BoundField DataField="_Group" HeaderText="_Group"
SortExpression="_Group" />
                <asp:BoundField DataField="SubGroup" HeaderText="SubGroup"
SortExpression="SubGroup" />
                <asp:BoundField DataField="_Order" HeaderText="_Order"
SortExpression="_Order" DataFormatString="{0:#,###.##}" />
                <asp:BoundField DataField="Item" HeaderText="Item" SortExpression="Item"
/>
                <asp:BoundField DataField="DateCreated" HeaderText="DateCreated"
SortExpression="DateCreated" DataFormatString="{0:d}" />
                <asp:BoundField DataField="DateModified" HeaderText="DateModified"
SortExpression="DateModified" />
                <asp:BoundField DataField="Value" HeaderText="Value"
SortExpression="Value" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM [config]">
        </asp:SqlDataSource>

    </div>
    </form>
</body>
</html>

Author
23 Jan 2007 8:09 PM
Pavel
Actually I found already why?
If someone wants to know here's the article
http://www.netomatix.com/development/GridViewDataFormatting.aspx

Show quoteHide quote
"Pavel" wrote:

> I have this code below and no format I put in property DataFormatString
> works. Why is it so?
>
> <%@ 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>
>         <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
> AutoGenerateColumns="False"
>             DataKeyNames="ID" DataSourceID="SqlDataSource1">
>             <PagerSettings Mode="NumericFirstLast" />
>             <Columns>
>                 <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
> ReadOnly="True"
>                     SortExpression="ID" >
>                     <ItemStyle Width="100px" />
>                 </asp:BoundField>
>                 <asp:BoundField DataField="_Group" HeaderText="_Group"
> SortExpression="_Group" />
>                 <asp:BoundField DataField="SubGroup" HeaderText="SubGroup"
> SortExpression="SubGroup" />
>                 <asp:BoundField DataField="_Order" HeaderText="_Order"
> SortExpression="_Order" DataFormatString="{0:#,###.##}" />
>                 <asp:BoundField DataField="Item" HeaderText="Item" SortExpression="Item"
> />
>                 <asp:BoundField DataField="DateCreated" HeaderText="DateCreated"
> SortExpression="DateCreated" DataFormatString="{0:d}" />
>                 <asp:BoundField DataField="DateModified" HeaderText="DateModified"
> SortExpression="DateModified" />
>                 <asp:BoundField DataField="Value" HeaderText="Value"
> SortExpression="Value" />
>             </Columns>
>         </asp:GridView>
>         <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
>             ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
> SelectCommand="SELECT * FROM [config]">
>         </asp:SqlDataSource>
>    
>     </div>
>     </form>
> </body>
> </html>
>
Author
27 Jan 2007 3:23 PM
Teemu Keiski
Yup, to summarize. HtmlEncode should be false.

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net


Show quoteHide quote
"Pavel" <pavelmagic***@yahoo.ca> wrote in message
news:F0CB32B3-C6C2-46C8-8DE4-4135BE0858C8@microsoft.com...
> Actually I found already why?
> If someone wants to know here's the article
> http://www.netomatix.com/development/GridViewDataFormatting.aspx
>
> "Pavel" wrote:
>
>> I have this code below and no format I put in property DataFormatString
>> works. Why is it so?
>>
>> <%@ 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>
>> <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
>> AutoGenerateColumns="False"
>> DataKeyNames="ID" DataSourceID="SqlDataSource1">
>> <PagerSettings Mode="NumericFirstLast" />
>> <Columns>
>> <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
>> ReadOnly="True"
>> SortExpression="ID" >
>> <ItemStyle Width="100px" />
>> </asp:BoundField>
>> <asp:BoundField DataField="_Group" HeaderText="_Group"
>> SortExpression="_Group" />
>> <asp:BoundField DataField="SubGroup" HeaderText="SubGroup"
>> SortExpression="SubGroup" />
>> <asp:BoundField DataField="_Order" HeaderText="_Order"
>> SortExpression="_Order" DataFormatString="{0:#,###.##}" />
>> <asp:BoundField DataField="Item" HeaderText="Item" SortExpression="Item"
>> />
>> <asp:BoundField DataField="DateCreated" HeaderText="DateCreated"
>> SortExpression="DateCreated" DataFormatString="{0:d}" />
>> <asp:BoundField DataField="DateModified" HeaderText="DateModified"
>> SortExpression="DateModified" />
>> <asp:BoundField DataField="Value" HeaderText="Value"
>> SortExpression="Value" />
>> </Columns>
>> </asp:GridView>
>> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
>> ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
>> ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
>> SelectCommand="SELECT * FROM [config]">
>> </asp:SqlDataSource>
>>
>>     </div>
>>     </form>
>> </body>
>> </html>
>>