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];
6 Réponses :
Dim id As Guid = GridView1.DataKeys(row.RowIndex).Value Dim email As String = CType(row.Cells(2), DataControlFieldCell).Text
Pas de solution avec ASP: Templatefield - ItemTemplate code>?
Référez-vous @ chưa BIếT Réponse pour le champ itemTemplate.
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
}
}
Il manque un ) code> sur = (gridviewrow code> en réponse
Essayez celui-ci ..
GridViewRow gvRow = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer); int rowIndex=gvRow.RowIndex
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
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>
Ceci est la solution correcte, comme documenté sur le Page MSDN sur RowCommand code> : La classe Buttonfield renonce automatiquement la propriété CommandArgument avec la valeur d'index appropriée. I>
@ROMIL: votre code en C #: (linkbutton est le bouton de modèle). em> p> p> P>
Valable pour ASP: Templatefield - ItemTemplate Code>
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;
}