asp.net 網頁程式設計 用 c#) - csie.ntu.edu.twr95077/aspnet/ch2.pdftarget –設定連結 ......

80
ASP.NET 網頁程式設計 (使 C#) CSIE NTU 1

Upload: vanthuy

Post on 11-Apr-2018

232 views

Category:

Documents


6 download

TRANSCRIPT

  • ASP.NET ( C#)

    CSIE NTU

    1

  • LinkButton 2

    LinkButton Button

    TextVisible

    Click

  • HyperLink 3

    HyperLink

    TextImageUrl()NavigateUrlTarget

    _blank_parent frameset _search_self_top

  • sample2-a14

    protected void Page_Load(object sender,

    System.EventArgs e){

    yahooHL.NavigateUrl = "http://tw.yahoo.com";yahooHL.Target = "_blank";

    }

  • Image 5

    Image

    ImageUrlAlternateText

    Height Width Height Width

  • sample2-b16

    ImageUrl Image

  • ImageButton 7

    ImageButton Button

    ImageUrlAlternateText

    Click(

    )

  • sample2-a2 (1)8

    onmouseover onmouseout

    HTML

  • sample2-a2 (2)9

    WebForm1.aspxprotected void carIB_Click(object sender,

    System.Web.UI.ImageClickEventArgs e){

    if(e.X

  • sample2-b210

    Label Label Visible false Cookie Session

  • DropDownList 11

    DropDownList

    Items(items ListItemCollection )

    ( ListItem )AutoPostBack

    SelectedIndexChanged( AutoPostBack true)

  • ListItemCollection 12

    DropDownList items ListItemCollection ()

    exDropDownList1.Items[1]

    Count ListItem SelectedItemSelectedIndex

    Add (ListItemstring)ClearRemove (ListItemstring)RemoveAt (int)

  • ListItem 13

    ListItemCollection ListItem

    TextValueSelected

  • sample2-a3 (1)14

    struct star{

    public string name;public string country;public string imgUrl;

    }

  • sample2-a3 (2)15

    star[] myStar = new star[3];protected void Page_Load(object sender, System.EventArgs

    e){

    myStar[0].name = "S.H.E";myStar[0].country = "";myStar[0].imgUrl = "she.jpg";myStar[1].name = "";myStar[1].country = "";myStar[1].imgUrl = ".jpg";

  • sample2-a3 (3)16

    myStar[2].name = "";myStar[2].country = "";myStar[2].imgUrl = ".jpg";

    if(!IsPostBack){

    foreach(star starItem in myStar)starDDL.Items.Add(starItem.name);

    starDDL.AutoPostBack = true;changeInfo();

    }}

  • sample2-a3 (4)17

    protected void starDDL_SelectedIndexChanged(object sender,

    System.EventArgs e){

    changeInfo();}protected void changeInfo(){

    nameLB.Text = myStar[starDDL.SelectedIndex].name;countryLB.Text = myStar[starDDL.SelectedIndex].country;pictureImg.ImageUrl = myStar[starDDL.SelectedIndex].imgUrl;

    }

  • ListBox 18

    ListBox DropDownList

    Items

    ( ListItemCollection )SelectionMode

    SingleMultiple( Selected true)

  • sample2-a4 (1)19

    protected void purchaseBTN_Click(object sender,

    System.EventArgs e){

    shoppingLB.Items.Add(itemLB.SelectedItem);itemLB.Items.Remove(itemLB.SelectedItem);shoppingLB.SelectedIndex = -1;totalLB.Text = total().ToString();

    }

  • sample2-a4 (2)20

    protected void cancelBTN_Click(object sender,

    System.EventArgs e){

    itemLB.Items.Add(shoppingLB.SelectedItem);shoppingLB.Items.Remove(shoppingLB.SelectedItem);itemLB.SelectedIndex = -1;totalLB.Text = total().ToString();

    }

  • sample2-a4 (3)21

    protected int total(){

    int sum = 0;foreach(ListItem item in shoppingLB.Items){

    sum += int.Parse(item.Value);}return sum;

    }

  • sample2-b322

    C#

    JAVA

  • CheckBox 23

    CheckBox

    TextTextAlignChecked

    CheckedChanged( AutoPostBack true)

  • CheckBoxList 24

    CheckBoxList

    Items( ListItemCollection )

    RepeatColumnsRepeatDirection

    SelectedIndexChanged( AutoPostBack true)

  • RadioButton 25

    RadioButton

    TextTextAlignCheckedGroupName

    CheckedChanged( AutoPostBack true)

  • RadioButtonList 26

    RadioButton

    Items( ListItemCollection )

    RepeatColumnsRepeatDirection

    SelectedIndexChanged( AutoPostBack true)

  • sample2-a5 (1)27

    WebForm1.aspxprotected void submitBTN_Click(object sender,

    System.EventArgs e){

    Session.Add("name",nameTB.Text);Session.Add("sex",sex1RB.Checked?"":"");Session.Add("education", educationRBL.SelectedItem.Text);

  • sample2-a5 (2)28

    WebForm1.aspxstring hobby = "";foreach(ListItem item in hobbyCBL.Items)

    if(item.Selected) hobby+= item.Text +" ";

    if(hobby == "") hobby = "";Session.Add("hobby", hobby);

    Response.Redirect("WebForm2.aspx");}

  • sample2-a5 (3)29

    WebForm2.aspxprotected void Page_Load(object sender, System.EventArgs e){

    Response.Write(Session["name"].ToString());Response.Write(Session["sex"].ToString() + "!!");Response.Write("

    "+Session["education"].ToString() + "");Response.Write(" "+Session["hobby"].ToString());

    }

  • sample2-b430

    ListItem Value

  • Access (1)31

    [] [] []

  • Access (2)32

    []

  • Access (3)33

  • ADO .NET34

    ADO.NET .NET Framework

    ExMSSQLAccessExcelXML

    ADO.NET

  • .NET 35

    .NET

    .NET Data ProviderSQL .NET Data Provider

    System.Data.SqlClientMS-SQL

    OLE DB .NET Data ProviderSystem.Data.OleDb DbaseFoxProExcelAccessOracleAccess

    ODBC .NET Data Provider

    MySQL

  • DataAdapter 36

    DataAdapter DataSet

    FillUpdate

  • DataAdapter (1)37

    DataAdapter

  • DataAdapter (2)38

  • DataAdapter (3)39

    ACCESS Microsoft Jet 4.0 OLE DB Provider

  • DataAdapter (4)40

  • DataAdapter (5)41

  • DataAdapter (6)42

    SQL

  • DataAdapter (7)43

    SQL SQL

  • DataAdapter (8)44

  • DataAdapter (9)45

    SQL

  • DataAdapter (10)46

    DataAdapter

  • DataAdapter (11)47

    DataAdapter DataSet ()

  • DataAdapter (12)48

    DataSet ()DataAdapter Fill DataSet

  • DataGrid (1)50

    DataGrid

    DataSourceAutoGenerateColumnsColumns

    DataBind

  • DataGrid (2)51

    DataSource

  • sample2-a652

    DataGrid

    protected void Page_Load(object sender, System.EventArgs e)

    {DataGrid1.DataBind();

    }

  • sample2-b553

    DataGrid

    DataAdapter

  • 54

  • 55

    DataGrid

  • DataGrid

  • 57

    ()

    () SelectedIndexChanged

    SelectedItem

  • DataGrid 58

    DataGrid Items Cells

    Items DataGrid Cells

    DataGrid1.Items[1].Cells[3].Text;

  • sample2-a759

    DataGrid

    protected void Page_Load(object sender, System.EventArgs

    e){

    DataGrid1.DataBind();int total = 0;foreach(DataGridItem item in DataGrid1.Items)

    total += int.Parse(item.Cells[1].Text);totalLB.Text = total.ToString();

    }

  • sample2-b660

    AutoGenerateColumns false

  • 61

    () ()

    URL URL

    URL WebForm2.aspx?filename={0} URL {0}

  • sample2-a862

    protected void Page_Load(object sender, System.EventArgs e)

    { oleDbDataAdapter1.Fill(dataSet11);favoriteDG.DataBind();

    }

  • sample2-b763

    WebForm2 .aspx

    URL URL

  • 64

    () () (CommandName)

    ItemCommand ItemCommand e DataGrid

    EnableViewState false

  • sample2-a965

    protected void Page_Load(object sender, System.EventArgs e){

    itemDG.DataBind();}protected void itemDG_ItemCommand(object source,

    System.Web.UI.WebControls.DataGridCommandEventArgs e){

    shoppingLB.Items.Add(e.Item.Cells[1].Text+ "" +e.Item.Cells[2].Text);

    totalLB.Text = (int.Parse(totalLB.Text) + int.Parse(e.Item.Cells[2].Text)).ToString();

    }

  • sample2-b866

    sample2-a9

    CommandName Items FindByText

  • 67

    DataGrid

    (AllowPaging) true (PageSize) PageIndexChanged e NewPageIndex

    DataGrid CurrentPageIndex

  • sample2-b968

    PageIndexChanged DataGrid CurrentPageIndex

  • SQL Server

    SQL Server

  • (local)\sqlexpress

    Windows

    MyDB

  • SQL Server

  • SQL Server

    Microsoft SQL Server

  • (local)\sqlexpress

    Windows

    ADO_NET_DB

  • ADO_NET_DB

  • MySQL

    http://www.mysql.com

    MySQL Connector/NEThttp://www.mysql.com/products/connector/net

    MySQL Connector/ODBChttp://www.mysql.com/products/connector/odbc

  • MySQL Connector/NET

    WindowsMySQL.Data.dll

    C:\Program Files\MySQL\MySQL Connector Net 1.0.7\bin

    Imports MySql.Data.MySqlClientImports System.Data

  • MySQL Connector/NET

    ButtonclickPrivate Sub Button1_Click(ByVal sender As System.Object,

    ByVal e As System.EventArgs) Handles Button1.ClickDim cn As MySqlConnectionDim da As MySqlDataAdapterDim ds As New DataSetcn = New MySqlConnection("server=localhost; user id=root;

    password=mysql; database=mysql ")cn.Open()MessageBox.Show("" + _cn.State.ToString())cn.Close()

    End Sub

  • MySQL Connector/NET

    button