11
votes

Obtenir la valeur de la cellule GridView à RowCommand

J'ai besoin d'obtenir la valeur d'une cellule à partir de l'événement RowCommand, mais la valeur n'est pas dans le paramètre PRIMICKEKeyNames Paramètre de la grilleview.

J'ai actuellement: P>

    int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvCurrentBanners.Rows[index];


0 commentaires

6 Réponses :


11
votes
Dim id As Guid = GridView1.DataKeys(row.RowIndex).Value

Dim email As String = CType(row.Cells(2), DataControlFieldCell).Text

2 commentaires

Pas de solution avec ASP: Templatefield - ItemTemplate ?


Référez-vous @ chưa BIếT Réponse pour le champ itemTemplate.



1
votes
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Edit_Mob") {

        GridViewRow row = (GridViewRow (((ImageButton)e.CommandSource).NamingContainer);

        int RowIndex = row.RowIndex; // this find the index of row

        int varName1 = Convert.ToInt32(((Label)row.FindControl("lbl_mobile_id")).Text.ToString()); //this store the  value in varName1

        }
   }

1 commentaires

Il manque un ) sur = (gridviewrow en réponse



3
votes

Essayez celui-ci ..

GridViewRow gvRow = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
int rowIndex=gvRow.RowIndex


1 commentaires

Je ne vois pas comment cela pourrait fonctionner, car vous créez une nouvelle grilleViewOWOW, ne faisant pas référence à celui existant dans la grilleview



3
votes

int index = convert.toint32 (e.commandargument); p>

Il ne fonctionne que lorsque vous utilisez votre bouton dans GridView est P>

<Columns>   
     <asp:ButtonField ButtonType="Button" Text="Save"  CommandName="Select" /> 
</Columns>

1 commentaires

Ceci est la solution correcte, comme documenté sur le Page MSDN sur RowCommand : La classe Buttonfield renonce automatiquement la propriété CommandArgument avec la valeur d'index appropriée.



6
votes

@ROMIL: votre code en C #: xxx

(linkbutton est le bouton de modèle).


1 commentaires

Valable pour ASP: Templatefield - ItemTemplate



0
votes
if (e.CommandName == "EditDetails")
{
    mp1.Show();
    //LinkButton LnkEdit = (LinkButton)sender;
    GridViewRow gvrow = (GridViewRow)((Control)e.CommandSource).NamingContainer;
    Panel1.Visible = true;
    Uploaddocs.Visible = false;
    Label lblmobile = (Label)gvrow.FindControl("lblN_MobileNo") ;
    Label lblDeathDate = (Label)gvrow.FindControl("lblDEATHDT");
    Label lblCAUSEOFDEATH = (Label)gvrow.FindControl("lblCAUSEOFDEATH");
    Label lblPLACEOFDEATH = (Label)gvrow.FindControl("lblPLACEOFDEATH");
    // Label lblRemarks = (Label)gvrow.FindControl("lblpracticalcredits");
    Label lblBank = (Label)gvrow.FindControl("lblBank");
    Label lblBranch = (Label)gvrow.FindControl("lblBranch");
    Label lblIFSC = (Label)gvrow.FindControl("lblIFSC");
    txtMobile.Text = Convert.ToInt64(lblmobile.Text).ToString();       //May be BigInt
    txtdate.Text = lblDate.Text;
    //ddlReasons.SelectedIndex = Convert.ToInt32(lblCAUSEOFDEATH.Text);
    //ddlReasons.SelectedValue = lblCAUSEOFDEATH.Text;
    txtcausedeath.Text = lblCAUSEOFDEATH.Text;
    txtPlaceofdeath.Text = lblPLACEOFDEATH.Text;
    BindBank();
    ddlbank.SelectedItem.Text = lblBank.Text;             //Sdents
    txtAddrBank.Text = lblBranch.Text;
    txtIFSC.Text = lblIFSC.Text;
}

0 commentaires