Use crosspage in the gridview in Asp.net 2.0

Source: Internet
Author: User

In Asp.net 2.0, the crosspage function is added, that is, the first page can be easily accepted
For more information, see http://www.cnblogs.com/jackyrong/archive/2005/01/15/92472.html. Here, for example
For example, in a gridview, When you click the name of a person in the first column, and then jump to the second page, the specific information about this person is displayed on this page, this can be easily implemented using the cross page function.

Page A has a gridview:
<Asp: gridview id = "G" runat = "server"
Allowsorting = "true" autogeneratecolumns = "false" allowpaging = "true"
Pagesize = "50" onrowcommand = "g_onrowcommand">
<Columns>
<Asp: buttonfield headertext = "username"
Commandname = "select" datatextfield = "username"
Buttontype = "Link" </asp>
.....................

Write the following in the g_onrowcommand event:Code
Protected void g_onrowcommand (Object sender,
Gridviewcommandeventargs E)
{
If (E. commandname = "select ")
{
Int Index = convert. toint32 (E. commandargument );
Gridviewrow selectedrow = (gridviewrow) g. Rows [Index];

Linkbutton clickedlinkedbutton =
(Linkbutton) selectedrow. cells [0]. controls [0]);

Selectedusername = clickedbutton button. text;
Server. Transfer (".../../pages/search/usersummary. aspx", true );
}
}

Here, first obtain the record of the row selected by the user (obtain the index), and then obtain the connection content of the first column in The gridview, finally, use selectedusername to store the username in the record selected by the user .,
The selectedusername attribute is defined as follows:

Private string _ selectedusername;

Public String selectedusername
{
Get
{
Return _ selectedusername;
}
Set
{
_ Seletedusername = value;

}

}

Then in the second receiving page B. aspx, this design
<% @ Previouspagetype
Virtualpath = "~ /A .. aspx "%>

Protected void page_load (Object sender, eventargs E)
{
If (this. previouspage! = NULL)
{
Response. Write (this. previouspage. selectedusername );
}
}

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.