Actually GridView displays date with time only even though you store just date in database say 12/2/2003.
How to overcome this?
Use DataFormatString attribute of BoundField to format your data in your source code while you write bound fields code of GridView.
The below sample shows this:
< asp:BoundField DataField="StartDate" HeaderText="StartDate" DataFormatString="{0:d}" HtmlEncode="false" / >
Use DataFormatString attribute of BoundField to format your data in your source code while you write bound fields code of GridView.
The below sample shows this:
There is another way to achieve the same result.
you will write a query to retrieve data from database and you use SqlDataAdapter for this.
In the above shown GridView , the lines of code written to retrieve data are shown below:
private void GetData()
{
string squery="select projectid,projectname,projectdescp,startdate,enddate,
you will write a query to retrieve data from database and you use SqlDataAdapter for this.
In the above shown GridView , the lines of code written to retrieve data are shown below:
private void GetData()
{
string squery="select projectid,projectname,projectdescp,startdate,enddate,
clientname from project";
da = new SqlDataAdapter(squery, con);
bldr = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "Project");
GVProject.DataSource = ds.Tables["Project"];
GVProject.DataBind();
}
Instead of above query replace squery as shown below:
string squery=select projectid,projectname,projectdescp,convert(varchar,startdate,101) as startdate,convert(varchar,enddate,101) as enddate,clientname from project.
da = new SqlDataAdapter(squery, con);
bldr = new SqlCommandBuilder(da);
ds = new DataSet();
da.Fill(ds, "Project");
GVProject.DataSource = ds.Tables["Project"];
GVProject.DataBind();
}
Instead of above query replace squery as shown below:
string squery=select projectid,projectname,projectdescp,convert(varchar,startdate,101) as startdate,convert(varchar,enddate,101) as enddate,clientname from project.
1 comment:
Post a Comment