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
}