First, add a button in the template column to select the row. The code on the page is as follows:
<Asp: The gridview id = "gdview" runat = "server" cellpadding = "4" forecolor = "#333333" gridlines = "NONE"
Height = "176px" width = "380px" onrowdatabound = "gdview_rowdatabound" onselectedindexchanging = "gdview_selectedindexchanging">
<Footerstyle backcolor = "#1c5e55" font-bold = "true" forecolor = "white"/>
<Rowstyle backcolor = "# e3eaeb"/>
<Pagerstyle backcolor = "#666666" forecolor = "white" horizontalalign = "center"/>
<Selectedrowstyle backcolor = "# c5bbaf" font-bold = "true" forecolor = "#333333"/>
<Headerstyle backcolor = "#1c5e55" font-bold = "true" forecolor = "white"/>
<Editrowstyle backcolor = "#7c6f57"/>
<Alternatingrowstyle backcolor = "white"/>
<Columns>
<Asp: templatefield>
<Itemtemplate>
<Input id = "btnlocation" type = "button" value = "locate" onclick = "select ()" style = "height: 20px"/>
</Itemtemplate>
</ASP: templatefield>
</Columns>
</ASP: gridview>
The script code is as follows:
// Obtain the value of the specified column in the selected row in the gridview.
Function select ()
{
// Obtain the mouse clicking Element
VaR E = event. srcelement;
// Obtain the row number of the row where the element is located (the row number of the header starts from 0 ). Note: parentelement is only applicable to IE browsers, while parentnode complies with Dom standards.
// Var rowindex = E. parentelement. parentelement. rowindex;
VaR rowindex = E. parentnode. parentnode. rowindex;
// Obtain the gridview Control
VaR gdview = Document. getelementbyid ("<% = gdview. clientid %> ");
// Obtain the values of the specified columns of the selected row.
VaR value = gdview. Rows (rowindex). cells (column number). innertext;
}