Select rows in the Asp.net gridview template Column

Source: Internet
Author: User

Most of the functions are implemented through the template column. To facilitate selection and deletion, the built-in functions and methods are used, which can be easily implemented without any major problems found; however, when deployed to the server, it is found that the selection is not text, but "select", and the reason is not found. It must be implemented through the template column later.
When changed to the template column implementation, it was found that the gv_sjy_rowcommand event could not get the row index value through E. commandargument. There are only two ways to do this:
First:

CopyCode The Code is as follows: <asp: linkbutton id = "btnselect" runat = "server" causesvalidation = "false" commandname = "select" text = "select" commandargument = "<% # (gridviewrow) container ). rowindex %> "> </ASP: linkbutton>

Add the red part before using int rowindex = convert in the background. toint32 (E. commandargument); obtain the index value of a row
type 2: copy Code the code is as follows: protected void gv_sjy_rowcommand (Object sender, gridviewcommandeventargs E)
{< br> If (E. commandname = "select")
{< br> gridviewrow gvrow = (gridviewrow) (linkbutton) E. commandsource ). parent. parent);
int rowindex = gvrow. rowindex; // obtain the selected row index
txtsjyxh. TEXT = dt2.rows [rowindex] ["sjyxh"]. tostring ();
}< BR >}

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.