<%# Eval("Active").ToString().Equals("True") ? "Yes" : "No" %>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

In the above code snippet, on the .aspx page we have a GridView with asp:BoundField & asp:TemplateField (this is used to display the column data in the format we want or is used to display custom data. In this case we have displayed a CheckBox as the first column and Yes/No as the last column based on Active column value from the database). We have set AutoId (primary key of the table) as the DataKeyNames that we will use to identify the selected row of the GridView.

CheckBox chk = (CheckBox)row.FindControl("chkSelect");

if (chk.Checked)

{

// get the selected AutoId and cells text

}

}

}

The button fires GetSelectedRecords server side method, in which we have looped through all the rows of the GridView and found the CheckBox using FindControl method. In case the checkbox is checked by the user, we have retrieved the DataKey value of that row as well as the FirstName of that records (by retrieving 3rd cell text of that row).

Note: In this case, the selection is not maintained if user navigates to another page (this issue has been resolved in the next article, I will be publishing soon)