Presentation is loading. Please wait.

Presentation is loading. Please wait.

Controls.

Similar presentations


Presentation on theme: "Controls."— Presentation transcript:

1 Controls

2 Controls Web Form Controls HTML Form Controls
HTML Server Controls (runat=server) Web Controls Validation Controls Rich Controls List controls HTML Form Controls

3 特殊屬性AutoPostBack 表示控制項內容或選取項目發生改變時,是否自動發生伺服器的自動回傳

4 CheckBox & CheckBoxList
AutoPostBack=True  當CheckBox有改變時會執行OnCheckedChanged

5 CheckBoxList 程式動態新增 CheckBoxList1.Items.Add("123");
Dim li1 As New ListItem li1 = New ListItem("item4", "4") CheckBoxList1.Items.Add(li1)

6 CheckBoxList 動作 End if If CheckBoxList1.Items(i).Selected Then
把AutoPostBack設定成 True Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxList1.SelectedIndexChanged Dim msg As String = "" Dim i As Integer = 0 For i = 0 To CheckBoxList1.Items.Count - 1 If CheckBoxList1.Items(i).Selected Then msg = msg + "press " + i.ToString() End If Next Response.Write(msg) End Sub

7 RadioButton & RadioButtonList
If RadioButtonList1.Items(i).Selected Then Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged Dim msg As String = "" Dim i As Integer = 0 For i = 0 To RadioButtonList1.Items.Count - 1 If RadioButtonList1.Items(i).Selected Then msg = msg + "press " + RadioButtonList1.Items(i).Text.ToString() End If Next Response.Write(msg) End Sub

8 DropDownList DropDownList1.Items.Clear()
DropDownList1.Items.Add("item1") DropDownList1.Items.Add("item2") Dim li1 As New ListItem li1=new ListItem("item4","4") DropDownList1.Items.Add(li1)

9 Validation Controls

10 RequiredFieldValidator
驗證對象 錯誤訊息 Submit前檢查要驗證的控制項是否有輸入值

11 CompareValidator 驗證對象 錯誤訊息 Submit前檢查要驗證的控制項輸入值是否相等

12 RangeValidator 驗證對象 錯誤訊息 範圍 Submit前檢查要驗證的控制項輸入值是否在範圍內 要注意type的設定

13 RegularExpressionValidator
驗證對象 錯誤訊息 Submit前檢查要驗證的控制項輸入值是否符合設定的規則

14 RegularExpressionValidator
ValidationExpression 身分證 [A-Z](1|2)\d{8}

15 DataBind

16 資料繫結 by 程式 記得要 using System.Data.SqlClient; Imports System.Data
Imports System.Data.SqlClient Partial Class Default4 Inherits System.Web.UI.Page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conn As SqlConnection Dim cmd As SqlCommand, dr As SqlDataReader conn = New SqlConnection("data source= ;initial catalog=Northwind;user id=sa;password=12345;") conn.Open() cmd = New SqlCommand("select * from employees", conn) dr = cmd.ExecuteReader() DropDownList1.DataSource = dr DropDownList1.DataTextField = "LastName" DropDownList1.DataValueField = "EmployeeID" DropDownList1.DataBind() dr.Close() conn.Close() End Sub End Class

17 登入

18 登入判斷 // 檢查帳密正確性 SqlDataAdapter da=new SqlDataAdapter("select * from teacher where id='" + TextBox1.Text + "' and pwd='" + TextBox2.Text + "'",sqlConnection1); // 把資料從新的Adapter填入(FILL)Dataset DataSet ds2=new DataSet(); da.Fill(ds2,“teacher"); if(ds2.Tables[“teacher"].Rows.Count>0) { Session[“loginname”] = ds2.Tables[“teacher”].Rows[0][“name”]; //登入者姓名 }


Download ppt "Controls."

Similar presentations


Ads by Google