Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 3rd, 2006, 06:36 AM
Registered User
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to simonwilbert Send a message via Yahoo to simonwilbert
Default GridView

I'm trying to build a shopping cart using gridview. I wish at all times that the quantity column is a textbox and the customer at any point can modify the quantity :

1. user clicks in particular product quantity textbox
2. types in new quantity amount into the textbox.
3. clicks on "Update".

rather than gridview's normal method of having to click on "update" button to turn row into an editable mode...

1. user clicks on update button on relevant gridview row, then does above.

I have this at the mo linked to the gridview...

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

this works, but doesnt grab the new quantity value in "Quantity" control.

Simon Hurley
[email protected]
 
Old August 3rd, 2006, 09:02 AM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Checkout enable state or postbacks? Definitely its due to that only.

Rams
 
Old August 3rd, 2006, 09:45 AM
Registered User
 
Join Date: Aug 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to simonwilbert Send a message via Yahoo to simonwilbert
Default

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]
 
Old August 12th, 2006, 02:35 AM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yeah dude, I am having a similar problem when the new data after postback isnt available for some reason? Simon? have you been able to find a solution for this?

Thanks
s

 
Old August 12th, 2006, 02:40 AM
Registered User
 
Join Date: Aug 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dang it, I just fixed it. funny that I figured it out like 5 mts after I sent the earlier post! All I had to do was disable the GridViews Viewstate! Everything works just fine now!!

Good luck,
s






Similar Threads
Thread Thread Starter Forum Replies Last Post
Get GridView Cell Value Based on GridView Column stublair C# 2008 aka C# 3.0 0 September 4th, 2008 08:30 AM
Gridview user007 ASP.NET 2.0 Basics 2 June 22nd, 2008 09:30 AM
Gridview Thinlizzy ASP.NET 2.0 Basics 2 July 20th, 2007 08:33 AM
GridView Sheraz Khan ASP.NET 2.0 Basics 1 July 19th, 2007 10:28 AM
GridView heba ASP.NET 2.0 Professional 0 May 28th, 2007 01:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.