modernsky2003

好的VS2005代码

    public static DataTable GetListData()
    {
        DataTable ret = new DataTable();
        ret.Columns.Add(new DataColumn("Text"));
        ret.Columns.Add(new DataColumn("Value"));

        for (int n = 0; n < 4; n++)
        {
            DataRow dr = ret.NewRow();
            dr["Text"] = n.ToString();
            dr["Value"] = n.ToString();
            ret.Rows.Add(dr);
        }
        return ret;
    }

 this.BulletedList2.DataSource = Common.GetListData();
        BulletedList2.DataTextField = "Text";
        BulletedList2.DataValueField = "Value";
        BulletedList2.DataBind();


        if (!IsPostBack)
        {
            this.CheckBoxList1.DataSource = Common.GetListData();
            CheckBoxList1.DataTextField = "Text";
            CheckBoxList1.DataValueField = "Value";
            CheckBoxList1.DataBind();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string msg = " 选中项:<br><br>";
        for (int i = 0; i < CheckBoxList1.Items.Count; i++)
        {
            if (CheckBoxList1.Items[i].Selected)
            {
                msg += CheckBoxList1.Items[i].Text + "<br>";
            }
        }
        Response.Write(msg);

    }

<form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
            ErrorMessage="请正确填写邮件地址" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator></div>
    </form>


using System.Text;

public partial class ApplicationDemo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
            this.Application["Data"] = System.DateTime.Now.ToString();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        foreach (string str in this.Application.AllKeys)
        {
            sb.Append("键值:" + str);
            sb.Append("--对应的值为:" + Application[str]);
            sb.Append("<br/>");
        }
        this.lblInfo.Text = sb.ToString();
    }
}

        StringBuilder sb = new StringBuilder();
        foreach (string str in this.Request.Cookies.AllKeys)
        {
            sb.Append("键值:" + str);
            sb.Append("--对应的值为:" + Request.Cookies[str].Value);
            sb.Append("<br/>");
        }
        this.lblInfo.Text = sb.ToString();
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("利用Response.Write方法,输出的页面文字");
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Response.Cookies.Add(new HttpCookie("Data", System.DateTime.Now.ToString()));
        Response.Redirect("CookieDemo.aspx", false);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            this.Session["Data"] = System.DateTime.Now.ToString();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        StringBuilder sb = new StringBuilder();
        for (int n = 0; n < Session.Count;n++)
        {
            sb.Append("键值:" + Session.Keys[n]);
            sb.Append("--对应的值为:" + Session[n].ToString());
            sb.Append("<br/>");
        }
        this.lblInfo.Text = sb.ToString();
    }




using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Security.Principal;

public partial class UserDemo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        IPrincipal myPrincipal = this.User;
        String tableString = "<table border=1><tr><td>Name</td><td>";
        tableString += Server.HtmlEncode(myPrincipal.Identity.Name) + "</td></tr><tr><td>";
        tableString += "AuthenticationType</td><td>" + myPrincipal.Identity.AuthenticationType;
        tableString += "</td></tr><tr><td>IsAuthenticated</td><td>";
        tableString += myPrincipal.Identity.IsAuthenticated + "</td></tr></table>";
        Response.Write(tableString);
    }
}




posted on 2008-05-27 15:59  hekeneng  阅读(330)  评论(0编辑  收藏  举报

导航