Click here to Skip to main content
11,644,731 members (71,822 online)
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 2:36am
Mogya1.7K
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 680
1 jyo.net 494
2 Sergey Alexandrovich Kryukov 464
3 Afzaal Ahmad Zeeshan 418
4 CPallini 336
0 OriginalGriff 925
1 DamithSL 636
2 Afzaal Ahmad Zeeshan 622
3 Sergey Alexandrovich Kryukov 548
4 CPallini 521


Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | Last Updated 30 Apr 2013
Copyright © CodeProject, 1999-2015
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