2011-04-21 1 views
1
<asp:LinkButton ID="lblViewDetail" runat="server" style="text-decoration:underline;" OnCommand="ViewSummary" CommandArgument='<%#Eval("ShowlinkDetail") %>' Text='View Detail' /> 

J'ai un Menthod dans le fichier .cs et ce nom d'appel de méthode dans la zone de donnéesComment obtenir rowIndex dans GridView lorsque l'argument OnCommand utilisé dans le domaine

OnCommand="ViewSummary" 
private void ViewSummary() 
{ 
    //code 
} 

lorsque je clique dans la vue grille le contrôle de l'étiquette puis je veux obtenir le Rowindex.S'il vous plaît aider.

Répondre

1

il va retourner votre ligne actuelle. vous n'avez pas besoin de ramer index ..

if(e.CommandName == "") 
{ 
GridViewRow row = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer); 
} 
2

Le OnCommand pour votre linkbutton serait quelque chose comme ça

protected void lnk_Command(object sender, CommandEventArgs e) 
{ 
    // The Namingcontainer would be Gridrow 
    // You can get the rowindex in this fashion 
    ((sender as LinkButton).NamingContainer as GridViewRow).RowIndex  
} 
+0

+1 Ça m'a aidé. Merci. – Pankaj

0

Pour LinkButton:

CommandArgument='<%#((GridViewRow)Container).RowIndex%>' 

dans .cs :

protected void gv_CommDetails_RowCommand(object sender, GridViewCommandEventArgs e) 
     { 

      try 
      { 
       int index = Convert.ToInt32(e.CommandArgument); //Here you can get the index. 

       if (e.CommandName == "ViewSummary") 
       { 
        drp_Comm.Items.FindByValue(((HiddenField)gv_CommDetails.Rows[index].Cells[0].FindControl("hdn_CommCode")).Value).Selected = true; 
        txt_CommDescription.Text =gv_CommDetails.Rows[index].Cells[2].Text; 
       } 

      } 

      catch (Exception ee) 
      { 
       string message = ee.Message; 
      } 

     } 
Questions connexes