When I made a website last time, I encountered a problem: In the gridview bound with data, I need to read the data in the selected row and save it to a struct to pass the data to the next page. I asked some friends about the data and found no result, A friend said that he could pass the ID of the Data row to the next page and then bind it. At that time, he thought that this method would work, however, when I do this, I know that it is too troublesome to bind the ID passed on the page above. I believe it is more convenient to transfer the ID to the next page through the structure, so I have been searching for methods. This morning, I found that it is not difficult to obtain a row of data:
First, add a template column to select or obtain the row number of the selected row, and then use gridview1.rows [E. newselectedindex]. cells [0]. Text; to obtain the desired data unit. You only need to save no unit data as a struct.
Note that when setting the template column, I set the commandname attribute of the gridview to select (this is the default value) to get the row number.
Protected void gridviewincluselectedindexchanging (Object sender, gridviewselecteventargs E)
...{
Providerdetail pdetail = new providerdetail ();
Pdetail. sgamename = gridview1.rows [E. newselectedindex]. cells [0]. text;
Pdetail. sareaname = gridview1.rows [E. newselectedindex]. cells [1]. text;
Pdetail. sservername = gridview1.rows [E. newselectedindex]. cells [2]. text;
Pdetail. nmaxnum = gridview1.rows [E. newselectedindex]. cells [3]. text;
Pdetail. sprice = gridview1.rows [E. newselectedindex]. cells [4]. text;
Pdetail. smindeal = gridview1.rows [E. newselectedindex]. cells [5]. text;
Session ["PD"] = pdetail;
Response. Redirect ("~ /Providerdetails. aspx ");
}