SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Format grid columns for accepting date

    using windows forms

    currently wht i have fr binding the grid is

    in form load i hve
    sqlstr="
    select p.id , p.pname ,0 as QTY, p.RATE, AMOUNT, p.dtfrm as From_DT,p.dtto as To_DT from PRDT left join M_customer C On C.Cid = t.cust_id left join M_prdt P On P.id = t.id where t.cust_id = " & dropdown1.SelectedValue & "
    grid_trans.DataSource = ds1.Tables("trans")
    grid_trans.AllowUserToAddRows = False
    grid_trans.Columns(0).Visible = False


    grid_trans.Columns(5).DefaultCellStyle.Format = DateFormat.ShortDate
    grid_trans.Columns(6).DefaultCellStyle.Format = DateFormat.ShortDate



    thios is how i bind the grid on the form load
    from this tell me wht to do
    need to format the above columns for accepting date

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    In your database schema, how is p.dtfrm and p.dtto defined? Are they date/time columns or varchar?

  3. #3
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    they r datetime in database

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    It has been a while since I have done this, but there are two things to consider, 1) if your dataset is not strongly typed, you may need to use the itemdatabound event on the data grid to format the particular columns to be ShortDate. 2) or if it isn't strongly typed you can make a strongly typed dataset and use that, which would mean your current code should work.

    My gut is telling me that if you look into your dataset, you will see the type is of string because it isn't a strongly typed dataset. Otherwise, I don't see an obvious reason why your code isn't working.

  5. #5
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    still not able to do it.
    i jst want to bind a grid which has date column
    & the user shld be able to add date in each row of the date column
    if no date is added the default date of 01/01/1900 shld be saved in db

  6. #6
    SitePoint Member
    Join Date
    May 2012
    Location
    U.S.A.
    Posts
    2
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Have you ever tried the DateTimePicker?

  7. #7
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no i hAVNT TRIED datepicker
    i tried to enter value in the column as 05/05/2012

  8. #8
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,244
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by svibuk View Post
    no i hAVNT TRIED datepicker
    i tried to enter value in the column as 05/05/2012
    Ah, I would use a date picker, or try entering the date as 2012-05-05

  9. #9
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello
    not able to make it workable still.
    forget entering any data in the grid. even if the grid gets focus i getthe error
    in my db tbl which is binded to the grid has 2 fields with data type datetime


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •