Вот предложение Microsoft для этого
http://msdn.microsoft.com/en-us/library/bb907626.aspx#Y800
В gridview добавьте командную кнопку и преобразуйте ее в шаблон, затем дайте ему имя команды в этом случае " AddToCart ", а также добавьте CommandArgument "<% # (( GridViewRow) Контейнер) .RowIndex%> "
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="AddButton" runat="server"
CommandName="AddToCart"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
Text="Add to Cart" />
</ItemTemplate>
</asp:TemplateField>
Затем для создания по событию RowCommand вида сетки определите, когда сработала команда «AddToCart», и выполните оттуда все, что вы хотите
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AddToCart")
{
// Retrieve the row index stored in the
// CommandArgument property.
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button
// from the Rows collection.
GridViewRow row = GridView1.Rows[index];
// Add code here to add the item to the shopping cart.
}
}
** Одна ошибка, которую я сделал, заключалась в том, что я хотел добавить действия к кнопке моего шаблона вместо того, чтобы делать это непосредственно в событии RowCommand.