2.19. Allowing Selection Anywhere Within a GridView
You are implementing a
GridView that requires selection of a row, but you do not want to have a Select button in every row of your
GridView. What you really want is to allow the user to click anywhere within a row, like in a classic Windows application.
To every row in the
GridView, add a hidden Select button along with an
onclick event that performs the same action as if the hidden Select button were clicked:
Add a hidden
Linkso a hidden hyperlinked Select button is rendered in every row.
RowDataBoundevent, add an
onclickevent to the
GridViewrow that performs the same action as clicking the hidden Select button.
Figure 2-21. Output of GridView allowing selection anywhere
To allow selection of a row of data by clicking on it, you create a
GridView in the usual fashion but add a hidden
ButtonType attribute is set to
Link, and the
CommandName attribute is set to
Select. This causes the
GridView to be rendered with a hidden hyperlinked Select button in every row.
<asp:ButtonField ButtonType="Link" Visible="False" CommandName="Select" />… </Columns> ...