The GetDepartmentList() method returns the department names as a
DataSet. Using the FindControl() method, a reference to the DropDownList control
called drpDept, is retrieved. Next, the DataTextField and the DataValueField
properties of the DropDownList control are set properly. The FindByValue()
method is used to set the SelectedIndex property of the control to the appropriate
department name.
Displaying CheckBox in a GridView Control
We will now explore how to display a CheckBox in each of the records in a
GridView control. Following is the output of the application on execution.
Chapter 6
[ 147 ]
Note that there is a CheckBox control in the EmployeeID column of the GridView
control for each of its records displayed. When you select one or more check
boxes and click on the Click button control beneath the GridView control, the
employee names for the selected employee records are displayed as shown in the
following figure:
Let us now understand how we can achieve this. To display a CheckBox that is
bound to the EmployeeID column, we will use a TemplateField, as shown in the
following code snippet:
HeaderStyle-BackColor = "DarkOrange" HeaderText="EmployeeID">
In the Click event of the button control, we need to iterate through all the rows of
the GridView control and check whether the CheckBox for that row is checked.
Pages:
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152