Mega Code Archive

 
Categories / ASP.Net Tutorial / Data Binding
 

Put simple data binding expressions

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"      Inherits="Default"%> <%@ Import Namespace="System.Drawing" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>Simple Data Binding</title> </head> <body>     <div id="pageContent">         <form id="form1" runat="server">             <asp:DropDownList ID="SelColors" runat="server" AutoPostBack="True">                 <asp:ListItem>Orange</asp:ListItem>                 <asp:ListItem>Green</asp:ListItem>                 <asp:ListItem>Cyan</asp:ListItem>                 <asp:ListItem>Red</asp:ListItem>                 <asp:ListItem>Blue</asp:ListItem>             </asp:DropDownList>             <asp:Label runat="server" ID="lblColor" EnableTheming="false"                 ForeColor='<%# Color.FromName(SelColors.SelectedValue) %>'                 Text='<%# "<b>You selected: </b>" + SelColors.SelectedValue %>'  />              <asp:Label runat="server" ID="Label4" Text='<%# "on " + DateTime.Now %>' />              <hr />         </form>     </div> </body> </html> File: Default.aspx.cs using System; using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Drawing; public partial class Default : System.Web.UI.Page {     void Page_Load(object sender, EventArgs e)     {         DataBind();     } }