How can I find the control in the row command of grid view?
Actually there is no Row in GridViewCommandEventArgs, so you will need to get the row from the command source naming container
GridViewRow row = (GridViewRow)(((Control)e.CommandSource).NamingContainer);
then you will be able to use
TextBox myTextBox = row.FindControl("MyTextBoxId") as TextBox;
Hope this helps!
if your using LinkButton
LinkButton ctrl = e.CommandSource as LinkButton;
if (ctrl != null)
{
GridViewRow row = ctrl.Parent.NamingContainer as GridViewRow;
TextBox txtDescription = (TextBox)row.FindControl("txtDescription");
}
GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
Label lblProdId = (Label)row.FindControl(“lblproductId”);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With