Put simple data binding expressions : Expressions « Data Binding « ASP.NET Tutorial






<%@ 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();
    }
}








19.15.Expressions
19.15.1.Put simple data binding expressions
19.15.2.Binding Expression
19.15.3.Databind the result of a method call
19.15.4.DataList with data binding expression