Here is the Microsoft suggestion for this http://msdn.microsoft.com/en-us/library/bb907626.aspx#Y800
In gridview, add a command button and convert it to a template, and then give it the command name in this case " AddToCart ", and also add CommandArgument "<% # ((GridViewRow) Container) .RowIndex%>"
<asp:TemplateField> <ItemTemplate> <asp:Button ID="AddButton" runat="server" CommandName="AddToCart" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" Text="Add to Cart" /> </ItemTemplate> </asp:TemplateField>
Then, to create the RowCommand gridview event, specify when the "AddToCart" command is run, and do what you want from there
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "AddToCart") {
** One mistake I made was that I wanted to add actions to the button on the template instead of doing it directly on the RowCommand event.
Cesar Duran Feb 17 '11 at 4:12 2011-02-17 04:12
source share