Click here to Skip to main content
15,900,608 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
protected void BindData()
        {
            string strFirstName = "";
            string strLastName="";
            DateTime? dtStartDate = null;
            DateTime? dtEndDate = null;
            var PatientEvaluations = objPatient.GetAllPatientEvaluation(strFirstName,strLastName,dtStartDate,dtEndDate).AsQueryable();

            GridViewPatient.DataSource = PatientEvaluations;
            GridViewPatient.DataBind();
        }


this is my method

in database the start and endDate value is 12/12/1988

but when this method bind into my grid it display

12/12/1988 12:00:00AM

plz help me

i want to display
12/12/1988
Posted
Comments
ZurdoDev 18-Mar-13 10:23am    
You just need to add a dataformatstring to your grid column. Dates are actually a combination of date and time which is why "no time" is actually 12:00 AM.
Sergey Alexandrovich Kryukov 18-Mar-13 10:29am    
Right. I answered on time formatting, but did not mention DataFormatString, because OP did not even mention what grid view type is used, etc.
—SA
Matej Hlatky 18-Mar-13 10:27am    
Yes because .NET knows only DateTime structure and not Date. Have you tried to use StringFormat = d?
prince_rumeel 18-Mar-13 10:32am    
i use this all.but no result

There is no such thing as just date in .NET. However, there is a function Date which returns the same time as argument, with time of the day simply "truncated" to 12:00:00 midnight:
http://msdn.microsoft.com/en-us/library/system.datetime.date.aspx[^].

I believe you don't need it. Your only problem is that you try to show only the date on screen, but the time is also shown. You just need to learn formatting in general, and for this type:
http://msdn.microsoft.com/en-us/library/ht77y576.aspx[^],
http://msdn.microsoft.com/en-us/library/zdtaw1bw.aspx[^],
http://msdn.microsoft.com/en-us/library/8tfzyc64.aspx[^],
http://msdn.microsoft.com/en-us/library/az4se3k1.aspx[^],
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx[^].

That's it.

—SA
 
Share this answer
 
Comments
prince_rumeel 18-Mar-13 10:28am    
bro in my case as above i mention that my DAL class function also taking the parameter.

plz see it.

it is not permitting me to do my desire task
Sergey Alexandrovich Kryukov 18-Mar-13 10:34am    
And..?
—SA
ZurdoDev 18-Mar-13 10:36am    
Actually SQL2012 now has a Date data type and a time data type.
Sergey Alexandrovich Kryukov 18-Mar-13 10:38am    
I know, but the question was about C#. I didn't say "there is no such thing" I said "there is no such thing in .NET".
—SA
HTML
<div class="right" style="width: 166px; height: 19px;">
                                        <%# Eval("EvaluationDate", "{0:M-dd-yyyy}")%></div>



i solve it using this in my grid view
 
Share this answer
 
C#
protected void BindData()
        {
            string strFirstName = "";
            string strLastName="";
            DateTime? dtStartDate = null;
            DateTime? dtEndDate = null;
            var PatientEvaluations = objPatient.GetAllPatientEvaluation(strFirstName,strLastName,dtStartDate.ToString("dd/MM/yyyy"),dtEndDate.ToString("dd/MM/yyyy")).AsQueryable();

            GridViewPatient.DataSource = PatientEvaluations;
            GridViewPatient.DataBind();
        }


You try this, hope it will give expected result what you needed.
 
Share this answer
 
v2
Comments
prince_rumeel 18-Mar-13 10:26am    
public IQueryable GetAllPatientEvaluation(string strFirstName, string strLastName, DateTime? dtStartDate,DateTime? dtEndDate)
{
CastroDataContext objDAL = new CastroDataContext();
var varEvaluation_Question = objDAL.sp_GetPatientsEvaluation(strFirstName,strLastName,dtStartDate,dtEndDate).AsQueryable();
return varEvaluation_Question;
}



bro it is my DAL class function

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