Asp.net method summary of values from the gridview

Source: Internet
Author: User

Problems:

Gvfiles. Rows [E. rowindex]. cells [5]. Text. tostring (); no value. It may be converted to a template.

(Label) E. Row. findcontrol ("label1"). If findcontrol is used for text, its ID is changed, and its ID is dizzy... then datakeynames is used.

In the process of using the gridview, we often encounter this problem. We select a row to edit, or select a row to delete or ....... we need to obtain some information about the current row, especially the primary key information of the current row. The primary key information is generally not displayed on the page. At this time, we have three methods to deal with it.
The first method is to use datakeynames. Here we will focus on it.
The second is to use the commandargument attribute of the button to specify the required information.
The third is the oldest and most common method to display data using hidden methods.

Method 1: Use datakeynames. datakeynames can be either a column or multiple columns.
Foreground: datakeynames = "FID" bind a value
Background: gridview1.datakeys [E. Row. rowindex]. value. tostring ();

Foreground: datakeynames = "FID, fname" bind two values
Background: gridview1.datakeys [E. Row. rowindex]. Values [0]. tostring ();
Background: gridview1.datakeys [E. Row. rowindex]. Values [1]. tostring ();
Or
Background: gridview1.datakeys [E. Row. rowindex]. Values ["FID"]. tostring ();
Background: gridview1.datakeys [E. Row. rowindex]. Values ["fname"]. tostring ();

Method 2: Use the commandargument attribute of the button to specify the required information.

Typical Example: Download the attachment column (the link for displaying and downloading attachments is displayed, and the link for displaying and downloading attachments without attachments is blank)
<Asp: templatecolumn headertext = "Appendix">
<Headerstyle width = "7%" type = "codeph" text = "/codeph"> <Itemtemplate>
<Asp: linkbutton id = "linkbutton1" commandname = "Download" commandargument = '<% # databinder. eval (container. dataitem, "attached_file") %> 'runat = "server" visible = '<% # (databinder. eval (container. dataitem, "attached_file "). tostring ())! = "") %> '> Download </ASP: linkbutton>
</Itemtemplate>
</ASP: templatecolumn>

In the dghkstock_itemcommand event:
If ("Download" = E. commandname)
{
Mybc. systemovertime0 (); // determines whether the session has expired
Mybc. rightmanage ("16010500"); // determines whether the user has the permission to open the webpage.
Mybc. http_downloadfile (E. commandargument. tostring (); // path for storing attachments that obtain the current inventory information
}

 

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.