Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Display Format Error

Posted on 2014-01-20
2
Medium Priority
?
344 Views
Last Modified: 2014-01-21
Hi,

I have the below class with display format attribute for TimeSpan

where it has to display only hours and minutes

public partial class abc
    {
        [DataType(DataType.Time)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = @"{0:hh\:mm}")]
        public System.TimeSpan getTimes
        {
            get;
            set;
        }      
     
    }


and now i am calling it from button click event as below

 private void button1_Click(object sender, EventArgs e)
        {
            System.TimeSpan d = new System.TimeSpan();
            abc  obj = new abc();
            obj.getTimes = d;
            MessageBox.Show(obj.getTimes.ToString());
        }

 here after executing it is showing the time with hours , minutes and seconds

 but i want to display it with only hours and minutes , i don't want seconds

 could you please suggest me what is the wrong in above code, I am using mvc4 Razor

                   Many thanks
0
Comment
Question by:praveen1981
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 1500 total points
ID: 39796303
Hi,

DataFormatingString is for when you use the html helpers, like

    @Html.DisplayFor(m=>m.getTimes)

Open in new window


In your case, since you are using this in a messagebox, you should format it using the ToString:

MessageBox.Show(obj.getTimes.ToString(@"hh\:mm"));

Open in new window


Giannis
0
 

Author Closing Comment

by:praveen1981
ID: 39796363
Thanks.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question