Formatting a String in a DataGrid Column 
Author Message
 Formatting a String in a DataGrid Column

I am using VS.NET C# to create an ASP.NET Web application.

I have a Social Security # character (string) field that I am displaying in
a column of a DataGrid control.

The Columns page of the VS.NET DataGrid Properties dialog contains a box
labeled "Data Formatting Expression". What can I put into thatbox that will
format the Social Security # as 999-99-9999, the standard Social Security #
display format?

TIA,

Dave



Mon, 13 Dec 2004 22:10:52 GMT  
 Formatting a String in a DataGrid Column
Dave,

    The Data Formatting Expression is basically a string, much in the way
the format string that the static Format method on the String class takes
that your value is plugged into.

    So, depending on how you store the SS#, you will have to construct an
expression appropriately.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> I am using VS.NET C# to create an ASP.NET Web application.

> I have a Social Security # character (string) field that I am displaying
in
> a column of a DataGrid control.

> The Columns page of the VS.NET DataGrid Properties dialog contains a box
> labeled "Data Formatting Expression". What can I put into thatbox that
will
> format the Social Security # as 999-99-9999, the standard Social Security
#
> display format?

> TIA,

> Dave



Mon, 13 Dec 2004 22:27:53 GMT  
 Formatting a String in a DataGrid Column


Quote:
> I am using VS.NET C# to create an ASP.NET Web application.

> I have a Social Security # character (string) field that I am displaying
in
> a column of a DataGrid control.

> The Columns page of the VS.NET DataGrid Properties dialog contains a box
> labeled "Data Formatting Expression". What can I put into thatbox that
will
> format the Social Security # as 999-99-9999, the standard Social Security
#
> display format?

I was looking for a way to do this, and there probably is, but I couldn't
find it.

If worse comes to worse, you can implement the DataGrid's ItemDataBound
event. This is called when each row is data bound and the columns
have been filled with text (just before the rendering of the page).

You can get a reference to the item (row) and get the column with
the SS# and format the string the old fashioned way.

-c



Mon, 13 Dec 2004 22:32:20 GMT  
 Formatting a String in a DataGrid Column

just a recomendation, reply on TOP of the message so we don't have to scroll to bottom to see it.
      _________________
      Terry Mulvany
      iStartSchool, Inc.
      626.795.8765




  > I am using VS.NET C# to create an ASP.NET Web application.
  >
  > I have a Social Security # character (string) field that I am displaying
  in
  > a column of a DataGrid control.
  >
  > The Columns page of the VS.NET DataGrid Properties dialog contains a box
  > labeled "Data Formatting Expression". What can I put into thatbox that
  will
  > format the Social Security # as 999-99-9999, the standard Social Security
  #
  > display format?

  I was looking for a way to do this, and there probably is, but I couldn't
  find it.

  If worse comes to worse, you can implement the DataGrid's ItemDataBound
  event. This is called when each row is data bound and the columns
  have been filled with text (just before the rendering of the page).

  You can get a reference to the item (row) and get the column with
  the SS# and format the string the old fashioned way.

  -c



Tue, 14 Dec 2004 01:08:21 GMT  
 Formatting a String in a DataGrid Column
What I've done is create Template Columns for the DataGrid... you'd
create a class that implements System.Web.UI.ITemplate and the code
would look something like this..

using System;

namespace Cte_Net.Templates
{
        /// <summary>
        /// Summary description for EditTemplate.
        /// </summary>
        public class TextboxTemplate: System.Web.UI.ITemplate
        {
                private string columnName = null;
                private string controlName = null;

                public TextboxTemplate(string newColumnName)
                {
                        columnName = newColumnName;
                }

                public TextboxTemplate(string newControlName, string newColumnName)
                {
                        columnName = newColumnName;
                        controlName = newControlName;
                }

                public void InstantiateIn(System.Web.UI.Control container)
                {
                        System.Web.UI.WebControls.TextBox label = new
System.Web.UI.WebControls.TextBox();
                        label.DataBinding += new EventHandler(this.BindLabel);

                        container.Controls.Add(label);
                }

                public void BindLabel(Object sender, EventArgs e)
                {
                        System.Web.UI.WebControls.TextBox label =
(System.Web.UI.WebControls.TextBox)sender;
                        System.Web.UI.WebControls.DataGridItem container =
(System.Web.UI.WebControls.DataGridItem)label.NamingContainer;

                        label.Text = ((System.Data.DataRowView)container.DataItem)[columnName].ToString().Trim();
                        label.ID = controlName;
                }
        }

Quote:
}

Then add the the template column to the DataGrid.

Hope that helps,
DeionXxX

Quote:



> > I am using VS.NET C# to create an ASP.NET Web application.

> > I have a Social Security # character (string) field that I am displaying
>  in
> > a column of a DataGrid control.

> > The Columns page of the VS.NET DataGrid Properties dialog contains a box
> > labeled "Data Formatting Expression". What can I put into thatbox that
>  will
> > format the Social Security # as 999-99-9999, the standard Social Security
>  #
> > display format?

> I was looking for a way to do this, and there probably is, but I couldn't
> find it.

> If worse comes to worse, you can implement the DataGrid's ItemDataBound
> event. This is called when each row is data bound and the columns
> have been filled with text (just before the rendering of the page).

> You can get a reference to the item (row) and get the column with
> the SS# and format the string the old fashioned way.

> -c



Tue, 14 Dec 2004 04:57:45 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. DataGrid, HyperLink Column, URL Format String

2. DataGrid, HyperLink Column, URL Format String

3. Formatting DataGrid columns

4. Formatting a column in the dataGrid

5. Help! - Custom Format DataGrid Columns

6. Help! - Custom Format DataGrid Columns

7. Help! - Custom Format DataGrid Columns

8. Sorting a date string column in a DataGrid

9. String Formatting in Datagrids

10. DataGrid Column Size

11. DataGrid with ComboBox in Column

12. datagrid columns

 

 
Powered by phpBB® Forum Software