DataFormatString questions...

Discussion in 'ASP .Net Datagrid Control' started by Michael Tanner, Nov 10, 2003.

  1. I have 2 formatting cases that I need to handle:

    Case 1: an eight digit account number stored in database as such - 12345678
    I need to display this in a boundcolumn as such - 1234-5678

    Case 2: a number is stored in the database as such - 42
    I need to display this in a boundcolumn as such - 0000042

    Can I use the DataFormatString property to accomplish these 2 cases and how?

    Thanks,
    Mike
     
    Michael Tanner, Nov 10, 2003
    #1
    1. Advertising

  2. Michael Tanner

    Aaron Weiker Guest

    Mike,
    Here is a brief sample that you can put into an ASP.NET page and it will
    demonstrate on how to do what you wanted. For more information look up
    String.Format() in the MSDN library.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/htm
    l/frlrfsystemstringclassformattopic2.asp

    <!-- ################################# -->

    <%@ Page Language="C#" Debug="True" %>
    <script runat="server">
    private void Page_Load(object sender, EventArgs e) {
    if (original.Text.Length > 0) {
    result1.Text = String.Format("{0:000000##}", int.Parse(original.Text));
    result2.Text = String.Format("{0:0000-0000}", int.Parse(original.Text));
    }

    }
    </script>
    <html>
    <head>
    </head>
    <body>
    <form runat="server">
    <asp:textbox id="original" runat="server" /> <br />
    <asp:label id="result1" runat="server" /> <br />
    <asp:label id="result2" runat="server" /> <br />
    <asp:button id="transform" runat="server" text="transform" />
    </form>
    </body>
    </html>
    <!-- ################################# -->

    Aaron Weiker
    http://aaronweiker.com/posts/174.aspx

    On Mon, 10 Nov 2003 15:31:54 -0500, Michael Tanner wrote:

    > I have 2 formatting cases that I need to handle:
    >
    > Case 1: an eight digit account number stored in database as such - 12345678
    > I need to display this in a boundcolumn as such - 1234-5678
    >
    > Case 2: a number is stored in the database as such - 42
    > I need to display this in a boundcolumn as such - 0000042
    >
    > Can I use the DataFormatString property to accomplish these 2 cases and how?
    >
    > Thanks,
    > Mike
     
    Aaron Weiker, Nov 14, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. frank

    DataFormatString Doesn't Work

    frank, Sep 5, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,169
    Luc Kumps
    Sep 5, 2003
  2. victor nguyen
    Replies:
    1
    Views:
    4,182
    Rutger Smit
    Sep 11, 2004
  3. Kenny

    How to use DataFormatString?

    Kenny, Dec 30, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    977
    John Saunders
    Dec 31, 2004
  4. Kenny

    DataFormatString

    Kenny, Dec 31, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,723
    Karl Seguin
    Dec 31, 2004
  5. Tarren
    Replies:
    7
    Views:
    5,099
    Tarren
    Jan 20, 2005
Loading...

Share This Page