Let's talk about my method first. It's not the best, but it'sCodeMinimum
One row:
E. Row. attributes [ " Onclick " ] = Clientscript. getpostbackclienthyperlink ( This . Gvusers, " Select $ " + E. Row. rowindex );
The specific method is to write this in the rowdatabound event of the gridview:
Protected Void Gvusers_rowdatabound ( Object Sender, gridviewroweventargs E)
{
E. Row. attributes [ " Onclick " ] = Clientscript. getpostbackclienthyperlink ( This . Gvusers, " Select $ " + E. Row. rowindex );
E. Row. attributes [ " Style " ] = " Cursor: pointer " ;
}
The principle is very simple, in ASP. NET page render, the selection, deletion, editing and other events of the gridview will generate simple PostBack parameters, respectively select $, update $, edit $...
This brings us great convenience. In the above example, the Select $ method is used.
Similar or almost identical to this method, there are:
From http://www.cnblogs.com/xioxu/articles/4732.16.html: (this park friend adds rowtype judgment, good !)
Protected Void Grdview_rowdatabound ( Object Sender, gridviewroweventargs E)
{
If (E. Row. rowtype = Datacontrolrowtype. datarow)
{
E. Row. Attributes. Add ( " Onclick " , " Javascript :__ dopostback (' " + Grdview. ID + " ', 'Select $ " + E. Row. rowindex + " '); " );
}
}
From http://www.cnblogs.com/easydata/articles/924947.html: (indeed, we can also add many client effects to row like this park friend, such as onmouseover)
Protected Override Void Render (htmltextwriter writer)
{
Foreach (Gridviewrow row In Gridview1.rows)
{
If (Row. rowtype = Datacontrolrowtype. datarow)
{
Row. attributes [ " Ondblclick " ] = Clientscript. getpostbackeventreference (gridview1, " Select $ " + Row. rowindex. tostring (), True );
Row. attributes [ " Style " ] = " Cursor: pointer " ;
Row. attributes [ " Title " ] = " Double-click a row " ;
}
}
Base . Render (writer );
}
OK. The above methods are implemented through JavaScript, but PostBack still occurs. If you want to implement a complete Ajax selection, please refer to the previous steps of Li yongjing.Article:
Http://www.cnblogs.com/lyj/archive/2008/05/10/1191275.html
The principle is to use hiddenfield to implement the "select" of the client (not the real select line ..)