Had a play with postbacks and enabling. doesnt seem to work. I've attached the gridview and datasource bits and restated the update function to. any suggestions??? basically. in each row of shopping cart, the quantity is shown in a textbox, and so user at any time can change quanity in textbox and click on a button in the row to call sql stored procedure to update shopping basket.
Sub src_Row_Command(sender As Object, e As GridViewCommandEventArgs)
Dim rowindex As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = my_Basket.Rows(rowindex)
Dim qtytb as Textbox = row.cells(5).findcontrol("Quantity")
Dim productid as label = row.cells(5).findcontrol("Product_ID")
response.write("Edit product '" & productid.text & "' in Basket '" & get_Basket_ID() & "' to quantity '" & qtytb.text & "'")
End Sub
...
<asp:sqldatasource
id="src_My_Basket"
ConnectionString="<%$ ConnectionStrings:DevonRose %>"
runat="server"
SelectCommand="Get_Basket_Items"
SelectCommandType="StoredProcedure"
DeleteCommand="Delete_Basket_Item"
DeleteCommandType="StoredProcedure"
UpdateCommand="Update_Basket_Item"
UpdateCommandType="StoredProcedure"
>
<SelectParameters>
<asp:ControlParameter Name="Basket_ID" ControlID="lbl_Basket_ID" PropertyName="Text" Type="String" />
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="Product_ID" Type="Int32" />
<asp:ControlParameter Name="Basket_ID" ControlID="lbl_Basket_ID" PropertyName="Text" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Product_ID" Type="Int32" />
<asp:ControlParameter Name="Basket_ID" ControlID="lbl_Basket_ID" PropertyName="Text" Type="String" />
<asp:Parameter Name="Quantity" Type="Int32" />
</UpdateParameters>
</asp:sqldatasource>
...
<asp:GridView autogeneratecolumns="false" id="my_basket" DataSourceID="src_My_Basket" runat="server"
onrowcreated="src_My_Basket_On_Row_Created"
onRowDeleted="src_Refresh_My_Basket"
onUpdateCommand="src_Update_Command"
EmptyDataText="There are no items in your shopping cart. If your registered with us then login to view your saved shopping cart."
onRowCommand="src_Row_Command"
DataKeyNames="Product_ID"
>
<columns>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
<asp:ButtonField buttontype="Link" commandname="Delete" text="X"/>
<asp:TemplateField HeaderText="Product ID" visible="false">
<ItemTemplate>
<asp:label id="product_ID" text=' <%# DataBinder.Eval(Container.DataItem, "Product_ID") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Item">
<ItemTemplate>
<%#Eval("Title")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Qty">
<ItemTemplate>
<asp:textbox id="Quantity" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Quantity") %>' />
</ItemTemplate>
</asp:TemplateField>
</columns>
</asp:GridView>
Simon Hurley
[email protected]