You
can use this property in the markup code in the .aspx file as shown
as follows:
DataKeyNames="EmployeeID"
Finding controls within a FormView control
Similar to the DetailsView control, you can use the FindControl()
method to find nested controls within a FormView control. The following
code snippet illustrates how this can be achieved.
if (FormView1.CurrentMode == FormViewMode.Edit ||
FormView1.CurrentMode == FormViewMode.Insert)
{
//Write your custom code here
}
Chapter 7
[ 199 ]
Note that the FormView control shown in the screenshot above has paging enabled
and it displays the details of the employees, one in each page. The following code
snippet shows the source code that gets generated in your .aspx file.
BackColor="White" BorderColor="Red" BorderStyle="None"
BorderWidth="1px" CellPadding="3" CellSpacing="2"
DataKeyNames="EmployeeID" DataSourceID="SqlDataSource1"
GridLines="Both">
ForeColor="White" />
EmployeeID:Text='<%# Eval("EmployeeID") %>'>
EmployeeName:runat="server" Text='<%# Bind("EmployeeName") %>'>
JoinDate:Text='<%# Bind("JoiningDate") %>'>
Salary:
DepartmentID:runat="server" Text='<%# Bind("DepartmentID") %>'>
And here is the markup code for the SqlDataSource control that we have used to
bind data to the FormView control.
Pages:
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191