Chapter7

Chia sẻ bởi Nguyễn Hữu Thường | Ngày 19/03/2024 | 9

Chia sẻ tài liệu: Chapter7 thuộc Công nghệ thông tin

Nội dung tài liệu:

1
CHAPTER 7
ASP.NET WEB SERVER CONTROLS


2
ASP.Net Web Server Control
Syntax ASP.Net Web Server Control:



Every element begin by prefix asp
Example:

Every element has both Id and Runat attribute.
3
You want to format control , you right-click control->properties.
4
Common Controls
Standard
Data
Navigation
Login
5
Standard

Label
Textbox
Button
CheckBox and Radio
FileUpload
List Controls group
AddRotator
XML
6
Label
Label server control is used to display text in the browser.
Property:
Text: is used set or get value

String strName=lblMsg.Text;
Or
lblMsg.Text=“Value”;
7
TextBox
Textbox is one of the main feautures of Web page. It permit user input data from Client.
Property:
TextMode: SingleLine, Password, MultiLine.
Text: set or get value

String strName=txtName.Text;
Or
txtName.Text=“Value”;
8
TextBox(cont)
AutoPostBack: has value true or false. When an an action on a Web page triggers an event.

String strName=btnName.Text;
Or
btnName.Text=“Value”;
10
Button
CommandName: permit multiple buttons your form all working from a single event.


12
Example Button



13
Checkbox and RadioButton

Property:
Text: get or set value
Checked: true or false
AutoPostBack: true or false
Events of Button:
OnCheckedChanged: event are created when user click CheckBox or Radiobutton Control

14
List Control group
DropDownList
ListBox
CheckBoxList
RadioButtonList
Each control can contain some options. Every option are created by ListItem tag.
15
List Control group (cont)



Or

text

16
List Control group (cont)

And
Pháp
Hoa

17
List Control group (cont)
Property:
AutoPostBack: true or false
Items: returns ListItem collection. Items array which contain every item. So, you want to access to item using index: Items[i].
Which i=0,n-1 (n=Items.Count).
Items.Count: return amount item
Items.Add(ListItem): add item in ListControl
Items.Remove(ListItem): remove item in ListControl
Items.Clear(): Remove all item.
Items[i].Selected: return true or false. Return true if Item are selected.
18
List Control group (cont)
Items[i].Text: Return item text .
Items[i].Value: Return item value .
SelectedIndex: return selected index.
SelectedItem:return selected item.
SelectedValue: return selected value.
DataSource: set value from DataSource such as DataTable,DataSet,Array,Collection,DataView
DataTextField: set text item from DataSource
DataValueField: set value item from DataSource
DataBind(): binding data to ListControl

19
List Control group (cont)

n=ListControl.Items.Count;
for(int i=0;i{
varName=ListControl.Items[i].Value;
}
20
List Control group (cont)

n=ListControl.Items.Count;
for(int i=0;i if(ListControl.Items[i].Selected==true)
{
varName=ListControl.Items[i].Value;
}
21
List Control group (cont)

foreach(ListItem obj in ListControl.Items)
{
varName=obj.Value;
}
22
List Control group (cont)

foreach(ListItem obj in ListControl.Items)
if(obj.Selected==true)
{
varName=obj.Value;
}
23
List Control group (cont)
Create ListControl(Id=lstName) 5 elements
ListItem obj=new ListItem() ;
lstName.Items.Clear();
for(int i=0;i<5;i++)
{
obj.Text=“T”+i;
obj.Value=i;
lstName.Items.Add(obj);
}
24
List Control group (cont)

foreach(ListItem obj in ListControl.Items)
if(obj.Selected==true)
{
ListControl.Items.Remove(obj);
}
25
List Control group (cont)
OleDbDataAdapter adap;
adap= new OleDbDataAdapter(strSQL,con);
DataSet ds=new DataSet();
Adap.Fill(ds);
ListControl.DataSource=ds;
// ListControl.DataSource=ds.Tables[0];
ListControl.DataTextField=“F1”;
ListControl.DataValueField=“F2”;
ListControl.DataBind();
* Một số tài liệu cũ có thể bị lỗi font khi hiển thị do dùng bộ mã không phải Unikey ...

Người chia sẻ: Nguyễn Hữu Thường
Dung lượng: | Lượt tài: 1
Loại file:
Nguồn : Chưa rõ
(Tài liệu chưa được thẩm định)