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. General Programming
  3. C#
  4. to validate date on datagrid template plz help.............

to validate date on datagrid template plz help.............

Scheduled Pinned Locked Moved C#
helptutorial
2 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.
  • P Offline
    P Offline
    P_Elza
    wrote on last edited by
    #1

    hi all i am inserting date to the text box on the datagrid template.There is 2 column for that. one receive date and the other due date. due date should be greater than receive date. and the date format is dd/mm/yyyy. how to validate this. since the date format is dd.mm.yyyy, am not able to compare it with different month.plz help me to solve this. am doing this from past 4 days. but didnt end up with a solution sample code is given below

    if(((TextBox)(dgDetailData.Items[total].Cells[7].Controls[1])).Text != "")
    {
    try
    {
    DateTime txt=Convert.ToDateTime(((TextBox)(dgDetailData.Items[total].Cells[6].Controls[1])).Text);
    DateTime tst=Convert.ToDateTime(((TextBox)(dgDetailData.Items[total].Cells[7].Controls[1])).Text);
    string date=month+"/"+day+"/"+year;
    if(DateTime.Compare(txt,tst)>0)
    {
    lblmsg.Text="error";
    lbl1.Text=date.ToString();

    } 
    

    else
    {
    lbl1.Text=txt.ToString();
    InsertParam[9].Value=Production.FORMATYMONDTIME(((TextBox)(dgDetailData.Items[total].Cells[7].Controls[1])).Text);
    }
    }
    catch(Exception err)
    {
    RegisterStartupScript("startup","window.alert('1.Error:"+err.ToString()+"')");
    }
    }
    else
    {
    InsertParam[9].Value=DBNull.Value;
    }

    -- modified at 22:46 Thursday 4th October, 2007

    C 1 Reply Last reply
    0
    • P P_Elza

      hi all i am inserting date to the text box on the datagrid template.There is 2 column for that. one receive date and the other due date. due date should be greater than receive date. and the date format is dd/mm/yyyy. how to validate this. since the date format is dd.mm.yyyy, am not able to compare it with different month.plz help me to solve this. am doing this from past 4 days. but didnt end up with a solution sample code is given below

      if(((TextBox)(dgDetailData.Items[total].Cells[7].Controls[1])).Text != "")
      {
      try
      {
      DateTime txt=Convert.ToDateTime(((TextBox)(dgDetailData.Items[total].Cells[6].Controls[1])).Text);
      DateTime tst=Convert.ToDateTime(((TextBox)(dgDetailData.Items[total].Cells[7].Controls[1])).Text);
      string date=month+"/"+day+"/"+year;
      if(DateTime.Compare(txt,tst)>0)
      {
      lblmsg.Text="error";
      lbl1.Text=date.ToString();

      } 
      

      else
      {
      lbl1.Text=txt.ToString();
      InsertParam[9].Value=Production.FORMATYMONDTIME(((TextBox)(dgDetailData.Items[total].Cells[7].Controls[1])).Text);
      }
      }
      catch(Exception err)
      {
      RegisterStartupScript("startup","window.alert('1.Error:"+err.ToString()+"')");
      }
      }
      else
      {
      InsertParam[9].Value=DBNull.Value;
      }

      -- modified at 22:46 Thursday 4th October, 2007

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      P_Elza wrote:

      since the date format is dd.mm.yyyy, am not able to compare it with different month

      Why not ? if (txt > tst) should work just fine. What's going wrong with this code when you step through it now ?

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      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