Analysis of Common ASP. NET technologies (II)

Source: Internet
Author: User
    • Pass a value between two gridview controls (method 1)

1. Set the column in gridview1 as the template column passed as the parameter value:

<Asp: templatefield headertext = "region" sortexpression = "territory">
<Itemtemplate>
<Asp: linkbutton id = "linkbutton1" runat = "server"
Oncommand = "gridviewpoliconclick"
Commandargument = '<% # (string) databinder. eval (container, "dataitem. territory") %>'
Commandname = "territorydrill"
TEXT = '<% # (string) databinder. eval (container, "dataitem. territory") %>'> </ASP: linkbutton>
</Itemtemplate>
<Itemstyle Height = "15px" horizontalalign = "Left" width = "150px"/>
</ASP: templatefield>

2. Obtain the row index number clicked in gridview1:

Protected void gridview1_onclick (Object sender, commandeventargs E)
{
String territoryname = E. commandargument. tostring (). Trim ();
Linkbutton lB = (linkbutton) sender;
Datacontrolfieldcell dcfc = (datacontrolfieldcell) lb. parent;
Gridviewrow gvr = (gridviewrow) dcfc. parent;
Gridview1.selectedindex = gvr. rowindex;
}

3. Set the parameter value of the data source of gridview2:

<Selectparameters>
<Asp: controlparameter controlid = "gridview1" name = "territory"
Propertyname = "selectedvalue" defaultvalue = "" type = "string"/>
</Selectparameters>

In this way, when you click the linkbutton control in a row in gridview1, The gridviewdomainonclick event is triggered, and the index number of the clicked row is obtained. When the value of gridview1.selectedindex changes, the databound event of the gridview2 control is triggered, and the index number of the clicked row is passed to the parameter of the data source of gridview2. in this way, you can click gridview1 to retrieve related data in gridview2.

    • Pass a value between two gridview controls (method 2)

The session variable is used to transmit values between two controls.

Set the parameter value of the formview1 Data source:

<Selectparameters>
<Asp: sessionparameter name = "employeeid" sessionfield = "employeeid" type = "int32"/>
</Selectparameters>

Protected void gridview2_onclick (Object sender, commandeventargs E)
{
String [] territoryname = E. commandargument. tostring (). Trim ();
Session ["employeeid"] = territoryname;
Formview1.databind ();
}

When you click the value column in the row in gridview2, take out the parameter of the linkbutton control in the row and save it to session ["employeeid"], and trigger the databound event of formview1. in this way, click gridview2 to retrieve relevant data in formview1.

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.