Click here to Skip to main content
12,402,666 members (71,017 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 30-Apr-13 2:36am
Mogya1.7K
Comments
Hard_Rockz 30-Apr-13 8:46am
   
hi,try to convert the date using CONVERT(VARCHAR,DATETIME_COLUMN_NAME,101)in your query...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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("{0Big Grin | :-D /M/yyyy}", DateTime.Now.ToShortDateString());
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();


and output is in dropdownlist as
24/04/2013

thanks
vilas
  Permalink  
Comments
patel_vijay 30-Apr-13 8:51am
   
Is your problem resolved ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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 ="{0Big Grin | :-D /M/yyyy}";
DropDownSingleEntryDate.DataSource = dt;
DropDownSingleEntryDate.DataBind();
con.Close();


and output is in dropdownlist as
24/04/2013

thanks
vilas
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100