Click here to Skip to main content
15,895,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i need to display only date in grid view but i am getting with time..

i am getting like this "9/22/2014 12:00:00 AM"

code is,

C#
protected void btnSave_OnClick(object sender, EventArgs e)
       {

           var objMessage = new ResourceMessage();
           var objHolidayBal = new HolidayBAL();
           var objHolidayBe = new HolidayBE
           {
               Holiday = txtHolidayName.Text.Trim(),
               HolidayDate = txtHolidayDate.Text.Trim() != "" ? Convert.ToDateTime(Convert.ToDateTime(txtHolidayDate.Text).ToString("d")) : DateTime.Now,
               Description = txtDescription.Text.Trim()
           };

           string number = objHolidayBal.InsertHoliday(objHolidayBe);

           string messages = objMessage.GenerateMessage(Convert.ToInt32(number ?? "0"), "Holiday", "inserted");

           ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "successscript", "alert('" + messages + "');", true);
           GetAllHoliday();
       }
Posted

1 solution

You set the DataFormatString property on your gridview column to just show the date portion. See http://forums.asp.net/t/1001482.aspx?DateTime+Format+in+gridview+colum[^] for an example.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900