DataGrid binding

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Franck Diastein

    DataGrid binding

    Hi,

    I'm binding a DataRead (obtained from a mssql SP)to a DataGrid, and one
    of the values is a date...

    The problem is that date is shown as dd/mm/yyyy hh:mm:ss and I would
    like to format it as dd/mm/yyyy...

    How can I do it ?

    I have seen some code using ItemDataBound event, but I can't manage to
    apply them...

    TIA
  • Eliyahu Goldin

    #2
    Re: DataGrid binding

    OK, keep trying to apply ItemDataBound event. What is the problem? To format
    date use DateTime.ToStri ng (formatString) method with format string
    "dd/mm/yyy".

    Eliyahu

    "Franck Diastein" <fdiastein@eusk altel.net> wrote in message
    news:u48T59p4EH A.4092@TK2MSFTN GP14.phx.gbl...[color=blue]
    > Hi,
    >
    > I'm binding a DataRead (obtained from a mssql SP)to a DataGrid, and one
    > of the values is a date...
    >
    > The problem is that date is shown as dd/mm/yyyy hh:mm:ss and I would
    > like to format it as dd/mm/yyyy...
    >
    > How can I do it ?
    >
    > I have seen some code using ItemDataBound event, but I can't manage to
    > apply them...
    >
    > TIA[/color]


    Comment

    • Franck Diastein

      #3
      Re: DataGrid binding

      My problem is that I can't find a sample for to retreive cell value and
      reasign to it a new value...

      Eliyahu Goldin wrote:
      [color=blue]
      > OK, keep trying to apply ItemDataBound event. What is the problem? To format
      > date use DateTime.ToStri ng (formatString) method with format string
      > "dd/mm/yyy".
      >
      > Eliyahu
      >
      > "Franck Diastein" <fdiastein@eusk altel.net> wrote in message
      > news:u48T59p4EH A.4092@TK2MSFTN GP14.phx.gbl...
      >[color=green]
      >>Hi,
      >>
      >>I'm binding a DataRead (obtained from a mssql SP)to a DataGrid, and one
      >>of the values is a date...
      >>
      >>The problem is that date is shown as dd/mm/yyyy hh:mm:ss and I would
      >>like to format it as dd/mm/yyyy...
      >>
      >>How can I do it ?
      >>
      >>I have seen some code using ItemDataBound event, but I can't manage to
      >>apply them...
      >>
      >>TIA[/color]
      >
      >
      >[/color]

      Comment

      • Eliyahu Goldin

        #4
        Re: DataGrid binding

        OK, suppose your column 0 contains the date you want to convert.

        private void dgSelection_Ite mDataBound(obje ct sender,
        System.Web.UI.W ebControls.Data GridItemEventAr gs e)
        {
        ListItemType itemType = e.Item.ItemType ;
        if ((itemType == ListItemType.Pa ger) ||
        (itemType == ListItemType.He ader) ||
        (itemType == ListItemType.Fo oter))
        {
        return;
        }
        e.Item.Cells[0].Text =
        System.Convert. ToDateTime(e.It em.Cells[0].Text ).ToString("dd/mm/yyyy");
        }


        Eliyahu

        "Franck Diastein" <fdiastein@eusk altel.net> wrote in message
        news:Oing0hq4EH A.2288@TK2MSFTN GP11.phx.gbl...[color=blue]
        > My problem is that I can't find a sample for to retreive cell value and
        > reasign to it a new value...
        >
        > Eliyahu Goldin wrote:
        >[color=green]
        > > OK, keep trying to apply ItemDataBound event. What is the problem? To[/color][/color]
        format[color=blue][color=green]
        > > date use DateTime.ToStri ng (formatString) method with format string
        > > "dd/mm/yyy".
        > >
        > > Eliyahu
        > >
        > > "Franck Diastein" <fdiastein@eusk altel.net> wrote in message
        > > news:u48T59p4EH A.4092@TK2MSFTN GP14.phx.gbl...
        > >[color=darkred]
        > >>Hi,
        > >>
        > >>I'm binding a DataRead (obtained from a mssql SP)to a DataGrid, and one
        > >>of the values is a date...
        > >>
        > >>The problem is that date is shown as dd/mm/yyyy hh:mm:ss and I would
        > >>like to format it as dd/mm/yyyy...
        > >>
        > >>How can I do it ?
        > >>
        > >>I have seen some code using ItemDataBound event, but I can't manage to
        > >>apply them...
        > >>
        > >>TIA[/color]
        > >
        > >
        > >[/color][/color]


        Comment

        • Franck Diastein

          #5
          Re: DataGrid binding

          OK, that's the code I need... This code give me error with datetime
          converstion, but that's another story...

          Thanx

          Eliyahu Goldin wrote:
          [color=blue]
          > OK, suppose your column 0 contains the date you want to convert.
          >
          > private void dgSelection_Ite mDataBound(obje ct sender,
          > System.Web.UI.W ebControls.Data GridItemEventAr gs e)
          > {
          > ListItemType itemType = e.Item.ItemType ;
          > if ((itemType == ListItemType.Pa ger) ||
          > (itemType == ListItemType.He ader) ||
          > (itemType == ListItemType.Fo oter))
          > {
          > return;
          > }
          > e.Item.Cells[0].Text =
          > System.Convert. ToDateTime(e.It em.Cells[0].Text ).ToString("dd/mm/yyyy");
          > }
          >
          >
          > Eliyahu
          >
          > "Franck Diastein" <fdiastein@eusk altel.net> wrote in message
          > news:Oing0hq4EH A.2288@TK2MSFTN GP11.phx.gbl...
          >[color=green]
          >>My problem is that I can't find a sample for to retreive cell value and
          >>reasign to it a new value...
          >>
          >>Eliyahu Goldin wrote:
          >>
          >>[color=darkred]
          >>>OK, keep trying to apply ItemDataBound event. What is the problem? To[/color][/color]
          >
          > format
          >[color=green][color=darkred]
          >>>date use DateTime.ToStri ng (formatString) method with format string
          >>>"dd/mm/yyy".
          >>>
          >>>Eliyahu
          >>>
          >>>"Franck Diastein" <fdiastein@eusk altel.net> wrote in message
          >>>news:u48T59p 4EHA.4092@TK2MS FTNGP14.phx.gbl ...
          >>>
          >>>
          >>>>Hi,
          >>>>
          >>>>I'm binding a DataRead (obtained from a mssql SP)to a DataGrid, and one
          >>>>of the values is a date...
          >>>>
          >>>>The problem is that date is shown as dd/mm/yyyy hh:mm:ss and I would
          >>>>like to format it as dd/mm/yyyy...
          >>>>
          >>>>How can I do it ?
          >>>>
          >>>>I have seen some code using ItemDataBound event, but I can't manage to
          >>>>apply them...
          >>>>
          >>>>TIA
          >>>
          >>>
          >>>[/color][/color]
          >
          >[/color]

          Comment

          • Saravana

            #6
            Re: DataGrid binding

            Check out "Formatting Dates, Currency, and Other Data" section in this
            article,


            --
            -Saravana




            "Franck Diastein" <fdiastein@eusk altel.net> wrote in message
            news:%23Jcokgr4 EHA.3820@TK2MSF TNGP11.phx.gbl. ..[color=blue]
            > OK, that's the code I need... This code give me error with datetime
            > converstion, but that's another story...
            >
            > Thanx
            >
            > Eliyahu Goldin wrote:
            >[color=green]
            > > OK, suppose your column 0 contains the date you want to convert.
            > >
            > > private void dgSelection_Ite mDataBound(obje ct sender,
            > > System.Web.UI.W ebControls.Data GridItemEventAr gs e)
            > > {
            > > ListItemType itemType = e.Item.ItemType ;
            > > if ((itemType == ListItemType.Pa ger) ||
            > > (itemType == ListItemType.He ader) ||
            > > (itemType == ListItemType.Fo oter))
            > > {
            > > return;
            > > }
            > > e.Item.Cells[0].Text =
            > > System.Convert. ToDateTime(e.It em.Cells[0].Text ).ToString("dd/mm/yyyy");
            > > }
            > >
            > >
            > > Eliyahu
            > >
            > > "Franck Diastein" <fdiastein@eusk altel.net> wrote in message
            > > news:Oing0hq4EH A.2288@TK2MSFTN GP11.phx.gbl...
            > >[color=darkred]
            > >>My problem is that I can't find a sample for to retreive cell value and
            > >>reasign to it a new value...
            > >>
            > >>Eliyahu Goldin wrote:
            > >>
            > >>
            > >>>OK, keep trying to apply ItemDataBound event. What is the problem? To[/color]
            > >
            > > format
            > >[color=darkred]
            > >>>date use DateTime.ToStri ng (formatString) method with format string
            > >>>"dd/mm/yyy".
            > >>>
            > >>>Eliyahu
            > >>>
            > >>>"Franck Diastein" <fdiastein@eusk altel.net> wrote in message
            > >>>news:u48T59p 4EHA.4092@TK2MS FTNGP14.phx.gbl ...
            > >>>
            > >>>
            > >>>>Hi,
            > >>>>
            > >>>>I'm binding a DataRead (obtained from a mssql SP)to a DataGrid, and[/color][/color][/color]
            one[color=blue][color=green][color=darkred]
            > >>>>of the values is a date...
            > >>>>
            > >>>>The problem is that date is shown as dd/mm/yyyy hh:mm:ss and I would
            > >>>>like to format it as dd/mm/yyyy...
            > >>>>
            > >>>>How can I do it ?
            > >>>>
            > >>>>I have seen some code using ItemDataBound event, but I can't manage to
            > >>>>apply them...
            > >>>>
            > >>>>TIA
            > >>>
            > >>>
            > >>>[/color]
            > >
            > >[/color][/color]


            Comment

            Working...