Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to insert/update a row/cell in datagrid?

How to insert/update a row/cell in datagrid?

Scheduled Pinned Locked Moved ASP.NET
helptutorialquestionannouncement
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    skhan17
    wrote on last edited by
    #1

    I don't understand how to update the row into the Datagrid to display a specific date format ??

    [ds is my dataset]
    foreach (DataRow r in ds.Tables[0].Rows)
    {
    string dateString1 = r["First_Resurvey_Date"].ToString();
    DateTime dateTime=Convert.ToDateTime(dateString1);
    string [] dateStringArray= dateTime.GetDateTimeFormats();

    r\["First\_Resurvey\_Date"\]= dateStringArray\[6\]; **\[This doesn't work, I cannot just assign the specific value to a datagrid row/cell......I need help on how to do that\] \[dateStringArray\[6\], gives the date format as dd-MMM-YY, which is how I want to display my date in the application\]**
                       
    NotesLabel.Text= dateStringArray\[6\];
    NotesLabel.Visible=true;
    

    }
    DataView view = ds.Tables[0].DefaultView;
    resultsDatagrid.DataSource = view;
    resultsDatagrid.DataBind();
    resultsDatagrid.Visible = true;

    N 1 Reply Last reply
    0
    • S skhan17

      I don't understand how to update the row into the Datagrid to display a specific date format ??

      [ds is my dataset]
      foreach (DataRow r in ds.Tables[0].Rows)
      {
      string dateString1 = r["First_Resurvey_Date"].ToString();
      DateTime dateTime=Convert.ToDateTime(dateString1);
      string [] dateStringArray= dateTime.GetDateTimeFormats();

      r\["First\_Resurvey\_Date"\]= dateStringArray\[6\]; **\[This doesn't work, I cannot just assign the specific value to a datagrid row/cell......I need help on how to do that\] \[dateStringArray\[6\], gives the date format as dd-MMM-YY, which is how I want to display my date in the application\]**
                         
      NotesLabel.Text= dateStringArray\[6\];
      NotesLabel.Visible=true;
      

      }
      DataView view = ds.Tables[0].DefaultView;
      resultsDatagrid.DataSource = view;
      resultsDatagrid.DataBind();
      resultsDatagrid.Visible = true;

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      :wtf: RTFM This does nothing but attempt to assign the value if the 5th element in the array to the column, it does not do any date formating. string [] dateStringArray= dateTime.GetDateTimeFormats(); r["First_Resurvey_Date"]= dateStringArray[6]; To format a date you need to do something like DateTime.ToShortDateString or DateTime.ToString(...)


      only two letters away from being an asset

      S 1 Reply Last reply
      0
      • N Not Active

        :wtf: RTFM This does nothing but attempt to assign the value if the 5th element in the array to the column, it does not do any date formating. string [] dateStringArray= dateTime.GetDateTimeFormats(); r["First_Resurvey_Date"]= dateStringArray[6]; To format a date you need to do something like DateTime.ToShortDateString or DateTime.ToString(...)


        only two letters away from being an asset

        S Offline
        S Offline
        skhan17
        wrote on last edited by
        #3

        If you have read the code correctly, then you should notice that I have a string type 'dateString1' variable, which holds the string value of a date type data row from the datagrid**[string dateString1 = r["First_Resurvey_Date"].ToString(); ]. My understanding could be wrong. And then there is a DateTime type variable 'dateTime', which holds the DateTime type value of the String dateString1.[DateTime dateTime=Convert.ToDateTime(dateString1);]. And then the string array dateStringArray contains various date formats of the 'dateTime' variable from which I need to display [6].[string [] dateStringArray= dateTime.GetDateTimeFormats(); ]** I do understand that the formatting doesn't change the datarow from the datagrid. Now once I have got a specific format of the date I want to display to the user, I was looking for a way to display that specific format into the datagrid. Please let me know if there is any way to do that, I hope I conveyed correctly what I want to do. Thanks in advance.

        N 1 Reply Last reply
        0
        • S skhan17

          If you have read the code correctly, then you should notice that I have a string type 'dateString1' variable, which holds the string value of a date type data row from the datagrid**[string dateString1 = r["First_Resurvey_Date"].ToString(); ]. My understanding could be wrong. And then there is a DateTime type variable 'dateTime', which holds the DateTime type value of the String dateString1.[DateTime dateTime=Convert.ToDateTime(dateString1);]. And then the string array dateStringArray contains various date formats of the 'dateTime' variable from which I need to display [6].[string [] dateStringArray= dateTime.GetDateTimeFormats(); ]** I do understand that the formatting doesn't change the datarow from the datagrid. Now once I have got a specific format of the date I want to display to the user, I was looking for a way to display that specific format into the datagrid. Please let me know if there is any way to do that, I hope I conveyed correctly what I want to do. Thanks in advance.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          skhan17 wrote:

          I need help on how to do that] [dateStringArray[6], gives the date format as dd-MMM-YY, which is how I want to display my date in the application]

          You where not clear in what you were asking for. This appears you are asking how to format a date

          skhan17 wrote:

          r["First_Resurvey_Date"]=

          Nor is it clear for this context that you want a format and not a date. The name seems to imply a date. Override the DataBind event and set the value of the column directly rather trying iterate through the DataTable and change the value.


          only two letters away from being an asset

          S 1 Reply Last reply
          0
          • N Not Active

            skhan17 wrote:

            I need help on how to do that] [dateStringArray[6], gives the date format as dd-MMM-YY, which is how I want to display my date in the application]

            You where not clear in what you were asking for. This appears you are asking how to format a date

            skhan17 wrote:

            r["First_Resurvey_Date"]=

            Nor is it clear for this context that you want a format and not a date. The name seems to imply a date. Override the DataBind event and set the value of the column directly rather trying iterate through the DataTable and change the value.


            only two letters away from being an asset

            S Offline
            S Offline
            skhan17
            wrote on last edited by
            #5

            What exactly did you mean by overriding the dataBind()?

            N 1 Reply Last reply
            0
            • S skhan17

              What exactly did you mean by overriding the dataBind()?

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              I refer to my original response, RTFM. Understanding the tools you are working with help immensely. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basedataboundcontrol.databound.aspx[^]


              only two letters away from being an asset

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups