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: