title: Format Telephone Number in GridView
body: <p>I see another thread somewhat like my question at:</p>
  
  <p><a href="https://stackoverflow.com/questions/1180403/asp-net-gridview-column-formatting-telephone-number">ASP.NET GridView Column - formatting telephone number</a></p>
  
  <p>but i do not know if it answers my question as he is using code-behind to make the colum. All I did was insert the GridView control in visual studio. BTW, the data is being populated in the Grid, I am just trying to get the formatting set now.</p>
  
  <p>I am using Microsoft Visual Studio Professional 2010. (Also SQL Management Studio for my database but this information may not be needed, just trying to give enough to make sure what i am doing is understood)</p>
  
  <p>I am making a website in ASP.NET with Visual Basic.net code behind. </p>
  
  <p>The site is basically a contact list site.</p>
  
  <p>3 Text Box Fields. First Name, Last Name, Main Phone #.</p>
  
  <p>Add Record Button (Takes the information from the text boxes and inserts into a database)</p>
  
  <p>GridView that shows the database that is being populated with the information</p>
  
  <p>I have a "Main Phone Number" Column and this pulls a telephone number to show in GridView. The number is only 10 digits, no formatting...(i.e. 999-999-9999)</p>
  
  <p>I am trying to make GridView take the 9999999999 and make it (999) 999-9999</p>
  
  <p>If I look at the DataFormatString I have tried many combinations of "{0:(###) ###-####}" with and without the quotations and also with all zeroes instead of pound signs.</p>
  
  <p>Through my research it seemed that if I want to use DataFormatString I need to make my phone number in my database an int. So I deleted my table and re-created it from a varchar to an int. I get to the DataFormatString by clicking on Gridview Tasks (arrow at top right of GridView)... then "Edit columns"... then under "Selected Fields" I click the name of the column... "Main Phone Number" then on the under "CommandField properties" I scroll down to "DataFormatString".</p>
  
  <p>I hope I am not being too detailed. I have really appreciated all the help.</p>
  
  <p>I found this:</p>
  
  <p><a href="http://www.tek-tips.com/viewthread.cfm?qid=328173" rel="nofollow noreferrer">http://www.tek-tips.com/viewthread.cfm?qid=328173</a></p>
  
  <p>but i don't know how i would go about using it.. seeing as  how because my code was done by Visual Studio... some of it looks like this </p>
  
  <hr>
  
  <p>UPDATE: I posted the wrong code originally, either way, based off what I stated Kelsey was able to suggest an answer for me that worked.</p>
  
  <p>Below is my new code WITH the corrections that Kelly gave.</p>
  
  <pre><code>    &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
              DataKeyNames="EmpId" DataSourceID="SqlDataSource1" 
              EmptyDataText="There are no data records to display." CellPadding="4" 
          ForeColor="#333333" GridLines="None" Height="136px" Width="299px" 
                AllowSorting="True"&gt;
              &lt;AlternatingRowStyle BackColor="White" /&gt;
              &lt;Columns&gt;
                  &lt;asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /&gt;
                  &lt;asp:BoundField DataField="EmpId" HeaderText="EmpId" ReadOnly="True" 
                      SortExpression="EmpId" Visible="False" /&gt;
                  &lt;asp:BoundField DataField="FirstName" HeaderText="First Name" 
                      SortExpression="FirstName" /&gt;
                  &lt;asp:BoundField DataField="LastName" HeaderText="Last Name" 
                      SortExpression="LastName" /&gt;
  &lt;%--                &lt;asp:BoundField DataField="MainPhoneNumber" HeaderText="Main Phone Number" 
                      SortExpression="MainPhoneNumber" /&gt;--%&gt;
                      &lt;asp:TemplateField HeaderText="Main Phone Number"&gt; 
                  &lt;ItemTemplate&gt; 
                   &lt;asp:Literal ID="litPhone"  runat="server" Text='&lt;%# string.Format("{0:(###) ###-####}", Int64.Parse(Eval("MainPhoneNumber").ToString())) %&gt;' /&gt; 
                  &lt;/ItemTemplate&gt; 
                  &lt;/asp:TemplateField&gt; 
  
              &lt;/Columns&gt;
              &lt;FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /&gt;
              &lt;HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" /&gt;
              &lt;PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" /&gt;
              &lt;RowStyle BackColor="#FFFBD6" ForeColor="#333333" /&gt;
              &lt;SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" /&gt;
              &lt;SortedAscendingCellStyle BackColor="#FDF5AC" /&gt;
              &lt;SortedAscendingHeaderStyle BackColor="#4D0000" /&gt;
              &lt;SortedDescendingCellStyle BackColor="#FCF6C0" /&gt;
              &lt;SortedDescendingHeaderStyle BackColor="#820000" /&gt;
          &lt;/asp:GridView&gt;
  </code></pre>