Solved

Bind date into an APS.NET label

Posted on 2009-07-13
7
397 Views
Last Modified: 2012-05-07
Hello,
I have one lave in a ASP.NET form,
and i want it to show the date of now.
how can i make this?
thanks
0
Comment
Question by:Nyana22
  • 4
  • 2
7 Comments
 
LVL 28

Expert Comment

by:strickdd
Comment Utility
<asp:Label id="DateLabel" runat="server" Text="<%= DateTime.Now %>"/>
0
 

Author Comment

by:Nyana22
Comment Utility
didn't work,
i putted in the master page
0
 
LVL 15

Expert Comment

by:jinal
Comment Utility
Hello ,

It is not appearing in page or Label is displayed but date is not displayed ?

B'coz if you place Label control inside ContentPlaceHolder then in content page you add something to that content assosiated with content place holder than problem.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:Nyana22
Comment Utility
the label is displayed but not date
i want to put the label in master page, and not in a content
0
 
LVL 15

Expert Comment

by:jinal
Comment Utility

<asp:Label ID="Label1" runat="server">

        <%= DateTime.Now %>

        </asp:Label>

Open in new window

0
 
LVL 15

Expert Comment

by:jinal
Comment Utility
Another way

/* Master */

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    

</head>

<body>

    <form id="form1" runat="server">

    <div>        

        <asp:Label ID="Label1" runat="server" Text='<%# DateTime.Now %>'>        

        </asp:Label>        

        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">        

        </asp:ContentPlaceHolder>

    </div>

    </form>

</body>

</html>
 

/* Master.master.cs */
 

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;
 

public partial class MasterPage : System.Web.UI.MasterPage

{

    protected void Page_Load(object sender, EventArgs e)

    {

        Label1.DataBind();

    }

}

Open in new window

0
 
LVL 15

Accepted Solution

by:
jinal earned 500 total points
Comment Utility
One another way .. also try my previous two comments.



/* Master */

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    

</head>

<body>

    <form id="form1" runat="server">

    <div>        

        <asp:Label ID="Label1" runat="server" Text="">        

        </asp:Label>        

        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">        

        </asp:ContentPlaceHolder>

    </div>

    </form>

</body>

</html>

 

/* Master.master.cs */

 

using System;

using System.Collections.Generic;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

public partial class MasterPage : System.Web.UI.MasterPage

{

    protected void Page_Load(object sender, EventArgs e)

    {

        Label1.Text = DateTime.Now.ToString();          

    }

}

Open in new window

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now