Вам необходимо проверить, какая команда в строке GridView была нажата. Ваша разметка должна соответственно отображаться. Смотрите ЭГС ниже.
Получаемый вами e.CommandArgument может не соответствовать вашему нажатию кнопки.
В CodeBehind:
void GridView1_RowCommand(Object sender, GridViewCommandEventArgs e)
{
// If multiple buttons are used in a GridView control, use the CommandName property to determine which button was clicked.
if(e.CommandName=="Add")
{
// Convert the row index stored in the CommandArgument property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked by the user from the Rows collection.
GridViewRow row = CustomersGridView.Rows[index];
// additional logic...
}
// additional logic...
}
В разметке:
Также убедитесь, что вы правильно установили свой атрибут CommandArgument. Пример ниже:
<asp:Button (...) CommandArgument="<%# Container.DataItemIndex %>" />
ИЛИ использовать поле кнопки
<asp:ButtonField ButtonType="button" CommandName="Add" Text="Add" />