Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Sir ,

My procedure get the record of smalldatetime like this format
2013-04-16 00:00:00

how to show this dates in ShortDateString using asp.net and C#

con.Open();
// string caseTtl_qry = "select distinct( Case_Title) from tblLegealCases";
SqlCommand cmd = new SqlCommand("GetSingleEntryDates", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Empid", Session["Empid"]);
DataTable dt = new DataTable();

SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField = "attendance_date";
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();


thanks
vilas
Posted
Comments
Dilan Shaminda 30-Apr-13 8:46am    
hi,try to convert the date using CONVERT(VARCHAR,DATETIME_COLUMN_NAME,101)in your query...

I have use DataTextFormatString for formating string of dropdownlist

con.Open();
// string caseTtl_qry = "select distinct( Case_Title) from tblLegealCases";
SqlCommand cmd = new SqlCommand("GetSingleEntryDates", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Empid", Session["Empid"]);
DataTable dt = new DataTable();

SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField = "attendance_date";
DropDownSingleEntryDate.DataTextFormatString = string.Format("{0:d/M/yyyy}", DateTime.Now.ToShortDateString());
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();


and output is in dropdownlist as
24/04/2013

thanks
vilas
 
Share this answer
 
Comments
vijay__p 30-Apr-13 8:51am    
Is your problem resolved ?
I have use DataTextFormatString for formating string of dropdownlist

con.Open();
// string caseTtl_qry = "select distinct( Case_Title) from tblLegealCases";
SqlCommand cmd = new SqlCommand("GetSingleEntryDates", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Empid", Session["Empid"]);
DataTable dt = new DataTable();

SqlDataAdapter sqlDa = new SqlDataAdapter(cmd);
sqlDa.Fill(dt);
DropDownSingleEntryDate.DataTextField = "attendance_date";
DropDownSingleEntryDate.DataTextFormatString ="{0:d/M/yyyy}";
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();


and output is in dropdownlist as
24/04/2013

thanks
vilas
 
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