Web服务器控件表

 

部分示例前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebFormTest.Test" %>

<!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>
        DropDownList:<asp:DropDownList ID="ddlTest"  EnableViewState="false" runat="server">
        </asp:DropDownList>
        <br />
        ListBox:<asp:ListBox ID="lbx" runat="server" EnableViewState="false"></asp:ListBox>
        <br />
        CheckBox:<asp:CheckBox ID="cbx" runat="server" OnCheckedChanged="cbx_CheckedChanged"
            EnableViewState="false" AutoPostBack="true" />
        <br />
        CheckBoxList:<asp:CheckBoxList ID="cbl" runat="server" EnableViewState="false">
        </asp:CheckBoxList>
        <br />
        RadioButton:<asp:RadioButton ID="rdoYes" GroupName="choose" runat="server" />
        <asp:RadioButton ID="rdoNo" GroupName="choose" runat="server" />
        <br />
        Table:<asp:Table ID="tb" runat="server">
        </asp:Table>
        <br />
        <asp:Calendar ID="cal" runat="server" onselectionchanged="cal_SelectionChanged"></asp:Calendar>
        <br />
        <asp:FileUpload ID="file" runat="server"  />
        <asp:Button ID="btnUpload" runat="server"
            Text="上传" onclick="btnUpload_Click" />
    </div>
    
    </form>
</body>
</html>
View Code

 

部分示例后台cs代码:

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;

namespace WebFormTest
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //ListItem[] items = new ListItem[4];
            //items[0] = new ListItem("测试1", "1");
            //items[1] = new ListItem("测试2", "2");
            //items[2] = new ListItem("测试3", "3");
            //items[3] = new ListItem("测试4", "4");

            ListItem[] items = new ListItem[] {
                new ListItem("测试1","1"),
                new ListItem("测试2","2"),
                new ListItem("测试3","3")
            };


            ddlTest.Items.AddRange(items);
            ddlTest.SelectedIndex = 2;

            lbx.Items.AddRange(items);
            lbx.SelectionMode = ListSelectionMode.Single;
            lbx.Rows = 1;

            cbx.Text = "";

            cbl.Items.AddRange(items);

            rdoYes.Text = "";

            


        }

        protected void Button1_Click(object sender, EventArgs e)
        {
        }

        protected void cbx_CheckedChanged(object sender, EventArgs e)
        {
            if (cbx.Checked==true)
            {
                Response.Write("checkbox选中了");
            }
            else
            {
                Response.Write("checkbox未选中");
            }
        }

        protected void cal_SelectionChanged(object sender, EventArgs e)
        {
            Response.Write(cal.SelectedDate.ToString("yy-MM-dd"));
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (file.HasFile)
            {
                string path = file.FileName;
                file.SaveAs(path);
            }
        }
    }
}
View Code

 

posted @ 2013-11-29 11:01  IT浪潮之巅  阅读(176)  评论(0编辑  收藏  举报
   友情链接: 淘宝优惠券