Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 8th, 2004, 10:40 AM
Authorized User
 
Join Date: Mar 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Data Formatting in DataGrid Template Column

I have the following snippet of code is which I am trying to format a 10 digit phone number field for display in a datagrid, and it is not working. Any suggestions would be appreciated. (pardon the formatting). The format mask (itemTemplate) is not reflected in display for the datagrid info.

<asp:TemplateColumn SortExpression="u_phone" HeaderText="Phone">
 <ItemTemplate>
   <asp:Label id=Label8 runat="server" Width=80
      Text='<%# Convert.ToString(DataBinder.Eval(Container, "DataItem.u_phone", "{0:(###)###-####}")) %>' / >
    </ItemTemplate>
 <EditItemTemplate>
   <asp:TextBox id=etxtPhone runat="server" MaxLength=10 Width=80
      Text='<%# DataBinder.Eval(Container, "DataItem.u_phone", "{0:##########}") %>' />
</asp:TemplateColumn>


 
Old April 12th, 2004, 04:26 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

It should work.what's the datatype of phone field?
Try giving the format in Grid_ItemDataBound() method..

 
Old April 12th, 2004, 09:28 AM
Authorized User
 
Join Date: Mar 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Data Type of column is varchar.

 
Old April 14th, 2004, 07:25 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 326
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to Santhi Send a message via MSN to Santhi
Default

Hi try this one....
In aspx page
<asp:Label id=Label8 runat="server" Width="80" Text='<%# FormatText((string)DataBinder.Eval(Container, "DataItem.phone")) %>' >

 In the code behind write this function..
public string FormatText(string myText)
        {
            string strPhone = myText.ToString();

            //If the passed string has space or underscore String.Format doesn't work.
            strPhone = strPhone.Replace(" ","");
            strPhone = strPhone.Replace("-","");

            string strFormatedString = String.Format("{0:(###) ###-####}",Int64.Parse (strPhone));
            return strFormatedString;
        }






Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting datagrid column dates badgolfer VS.NET 2002/2003 12 August 9th, 2006 08:24 AM
Template Column in datagrid prankur ASP.NET 1.0 and 1.1 Professional 1 January 7th, 2006 05:20 PM
template column in datagrid p2pMember ASP.NET 1.0 and 1.1 Basics 1 November 18th, 2005 06:33 PM
Datagrid template column sonurijs ASP.NET 1.x and 2.0 Application Design 1 September 27th, 2005 12:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.