Select row of gridview by JavaScript)

Source: Internet
Author: User

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 ..)

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.