??? ??? ??? ??? ??? ??? ??? ??? ??? ??? ???
Working with List Controls in ASP.NET
[ 56 ]
We will now discuss how we can add list items to this control. Refer to the following
code snippet that illustrates how such a control can be constructed from your .aspx
page to display a list of static list items.
runat="server" OnClick="bListDept_Click">
The above code snippet illustrates how the BulletedList control named bListDept
can be declared in your .aspx web page in ASP.NET. Note that the Selected
property of the control is used to set the default selected list item from among the
collection of list items in the control.
You can also add list items to this control programmatically. Following is the code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bListDept.Items.Add(new ListItem("IT"));
bListDept.Items.Add(new ListItem("Sales"));
bListDept.Items.Add(new ListItem("Admin"));
bListDept.Items.Add(new ListItem("HR"));
bListDept.Items[0].Selected = true;
}
}
Selecting a List Item
Drag-and-drop a Label control onto your web form.
Pages:
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71