Editing in a gridview

Discussion in 'ASP .Net' started by Tina, Jan 19, 2007.

  1. Tina

    Tina Guest

    I'm in the RowDataBound event for a gridview. my money fields and dates
    are in unedited format. The following works fine but is this the easiest
    way? Isn't there a way to apply formating to the string without having to
    convert the string to its native type and then back to an edited string?

    double mydouble = double.Parse(e.Row.Cells[totalcharge].Text);
    e.Row.Cells[totalcharge].Text = mydouble.ToString("c");
    DateTime myDateTime = DateTime.Parse(e.Row.Cells[designdate].Text);
    e.Row.Cells[designdate].Text = myDateTime.ToShortDateString();
    Thanks,
    T
     
    Tina, Jan 19, 2007
    #1
    1. Advertising

  2. Tina

    dunny Guest

    Tina

    Unless you have row-specific rules you can avoid RowDataBound
    alltogether and change your column defs to something like:

    <asp:BoundField DataFormatString="{0:c}" DataField="totalcharge" ...
    <asp:BoundField DataFormatString="{0:d}" DataField="designdate"
    HtmlEncode="false"...

    Remember the HtmlEncode when formatting dates!

    Mark

    On Jan 19, 1:08 pm, "Tina" <> wrote:
    > I'm in the RowDataBound event for a gridview. my money fields and dates
    > are in unedited format. The following works fine but is this the easiest
    > way? Isn't there a way to apply formating to the string without having to
    > convert the string to its native type and then back to an edited string?
    >
    > double mydouble = double.Parse(e.Row.Cells[totalcharge].Text);
    > e.Row.Cells[totalcharge].Text = mydouble.ToString("c");
    > DateTime myDateTime = DateTime.Parse(e.Row.Cells[designdate].Text);
    > e.Row.Cells[designdate].Text = myDateTime.ToShortDateString();
    > Thanks,
    > T
     
    dunny, Jan 19, 2007
    #2
    1. Advertising

  3. Tina

    Tina Guest

    my data is created at run time.


    "dunny" <> wrote in message
    news:...
    > Tina
    >
    > Unless you have row-specific rules you can avoid RowDataBound
    > alltogether and change your column defs to something like:
    >
    > <asp:BoundField DataFormatString="{0:c}" DataField="totalcharge" ...
    > <asp:BoundField DataFormatString="{0:d}" DataField="designdate"
    > HtmlEncode="false"...
    >
    > Remember the HtmlEncode when formatting dates!
    >
    > Mark
    >
    > On Jan 19, 1:08 pm, "Tina" <> wrote:
    >> I'm in the RowDataBound event for a gridview. my money fields and
    >> dates
    >> are in unedited format. The following works fine but is this the easiest
    >> way? Isn't there a way to apply formating to the string without having
    >> to
    >> convert the string to its native type and then back to an edited string?
    >>
    >> double mydouble = double.Parse(e.Row.Cells[totalcharge].Text);
    >> e.Row.Cells[totalcharge].Text = mydouble.ToString("c");
    >> DateTime myDateTime = DateTime.Parse(e.Row.Cells[designdate].Text);
    >> e.Row.Cells[designdate].Text = myDateTime.ToShortDateString();
    >> Thanks,
    >> T

    >
     
    Tina, Jan 19, 2007
    #3
    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. Fred K. Augustine, Jr

    Editing with GridView control

    Fred K. Augustine, Jr, Nov 21, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    932
    Fred K. Augustine, Jr
    Nov 21, 2005
  2. misiek
    Replies:
    7
    Views:
    50,457
    Sri123
    Apr 8, 2011
  3. =?Utf-8?B?TWljaGFlbA==?=

    Gridview Newvalues are empy after editing

    =?Utf-8?B?TWljaGFlbA==?=, Apr 13, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,839
    =?Utf-8?B?TWljaGFlbA==?=
    Apr 13, 2006
  4. =?Utf-8?B?bWdvbnphbGVzMw==?=

    GridView Hierarchical View - Gridview in Gridview

    =?Utf-8?B?bWdvbnphbGVzMw==?=, May 9, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    18,022
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=
    May 9, 2006
  5. Replies:
    0
    Views:
    604
Loading...

Share This Page