In grdiview, the row number in rowcommand and multiple buttonfields are used for multiple selection.

Source: Internet
Author: User

1. Get the row number in rowcommand

There are two implementation methods

(1) bind the front-end.

< ASP: templatefield itemstyle - Horizontalalign = " Center " Itemstyle - Width = " 80px " >
< Itemtemplate >
< ASP: button ID = " Freezebutton " Text = " Freeze " Runat = " Server " Commandname = " Freeze " Commandargument = ' <% # Databinder. eval (container, "rowindex") %> ' Borderstyle = " Groove " Onclientclick = " Javascript: Return confirm ('OK? '); " />
</ Itemtemplate >

</ASP: templatefield>

<Asp: linkbutton.../> can be used instead of <asp: linkbutton...ASP: button.../>

Or use

Commandargument = ' <% # Container. dataitemindex %> '

(2) backend binding

In the rowdatabound event of girdview

// When binding, the row number is bound to the button.
Linkbutton BT =   New Linkbutton ();
BT = (Linkbutton) E. Row. cells [ 7 ]. Findcontrol ( " Btnlz " );
Bt. commandargument = E. Row. rowindex. tostring ();

Use Time:

Protected   Void Grdmember_rowcommand ( Object Sender, gridviewcommandeventargs E)
{
// Retrieve Index
Int Index = Convert. toint32 (E. commandargument );
Datakey key = Grdmember. datakeys [Index];
String TT = Key. value. tostring ();

// Button to determine
// Switch (E. commandname. tostring ())
// {
// Case "DD ":
// Dosomething ();
// Break;
// Case "LZ ":
// Dosomethingelse ();
// Break;

// }

}

 

 

All bind the index to the buttonCommandargument

 

2. Multiple buttonfields implement multiple options

Sometimes only one selectbutton cannot meet the requirements, but multiple selectbutton cannot be added. Solution: implement multiple buttonfields.

Front-endCode:

 

< ASP: templatefield showheader = " False " >
< Itemtemplate >
< ASP: linkbutton ID = " Btnlz " Runat = " Server " Causesvalidation = " False " Commandname = " LZ "
Text = " Resign " > </ ASP: linkbutton >
</ Itemtemplate >
</ ASP: templatefield >

< ASP: templatefield showheader = " False " >
< Itemtemplate >
< ASP: linkbutton ID = " Btndd " Runat = " Server " Causesvalidation = " False " Commandname = " Dd "
Text = " Transfer " > </ ASP: linkbutton >
</ Itemtemplate >
</ ASP: templatefield >

What's important is commandname = ""

In the rowcommand control of girdview, you can determine which button is pressed.

Protected   Void Grdmember_rowcommand ( Object Sender, gridviewcommandeventargs E)
{
// Retrieve Index
// Int Index = convert. toint32 (E. commandargument );
// Datakey key = grdmember. datakeys [Index];
// String TT = key. value. tostring ();

// Button to determine
Switch (E. commandname. tostring ())
{
Case   " Dd " :
Dosomething ();
Break ;
Case   " LZ " :
Dosomethingelse ();
Break ;

}

}

 

Final effect:

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.