Popular Posts
Remove file not in list ADD ... THEN ... UNTIL ... data: begin of SERIES, N1 type I value 10, N2 type I value 20, N3 type I value 30, N4 type I value 40, ... Join related table and count rows or sum sql server 2005 count rows: SELECT * FROM Table1 LEFT JOIN     (SELECT Level1ID, COUNT(Level2ID) AS Total FROM Table2 GROUP BY Level1ID) AS...
Blog Archive
Stats
Binding with page member
Usually we'll bind controls with data, like SqlDataSource or XMLDataSource. But I found that I could bind member in a container, too. Now, It's convenient to me binding members withing a container for display some messages.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Binding with a member.aspx.cs"
    Inherits="Binding_with_a_member" %>

<!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>Binding with page member</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FormView ID="FormView1" runat="server" DataKeyNames="ID" DataSourceID="SqlDataSource1">
            <ItemTemplate>
                <div style="text-align: center; font-size: xx-large; color: Red;">
                    <asp:Label ID="Label1" runat="server" Text='<%# GUID %>'></asp:Label>
                </div>
                <div style="text-align: center; font-size: xx-large; color: Blue;">
                    <asp:Label ID="Label2" runat="server" Text='<%# RandomNumber %>'></asp:Label>
                </div>
                <div style="text-align: center; font-size: xx-large; color: Green;">
                    <asp:Label ID="Label3" runat="server" Text='<%# DateTime.Now %>'></asp:Label>
                </div>
            </ItemTemplate>
        </asp:FormView>
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:brucedbConnectionString %>"
        SelectCommand="SELECT * FROM [GV]"></asp:SqlDataSource>
    </form>
</body>
</html>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Binding_with_a_member : System.Web.UI.Page
{
    protected string GUID;
    protected int RandomNumber;
    protected void Page_Load(object sender, EventArgs e)
    {
        GUID = Guid.NewGuid().ToString();
        RandomNumber = new Random().Next(100, 10000);
    }
}