Click here to Skip to main content
Rate this: bad
good
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 3:36am
Mogya1.6K
Comments
Hard_Rockz at 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 at 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
0 OriginalGriff 359
1 Maciej Los 290
2 Sergey Alexandrovich Kryukov 230
3 Shweta N Mishra 185
4 PIEBALDconsult 149
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2014
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