This is a migrated thread and some comments may be shown as answers.

shopping cart session bind to Grid

3 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ching-Yen
Top achievements
Rank 1
Ching-Yen asked on 21 Mar 2009, 10:59 AM
Hi,

We are trying to do something like Telerik online purchase check out list where user could update the quality by using combobox and also delete product as they wish.

We only manage to bind the session to the Grid, but, we are not able to bind the delete command and also the edit to the Grid item. The RadGrid1_ItemDeleted will never been fired.

Please advice.

Dim objDT As System.Data.DataTable 
Dim objDR As System.Data.DataRow 
 
Protected Sub RadGrid1_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
objDT = Session("Cart"
RadGrid1.DataSource = objDT 
End Sub 
 
Protected Sub RadGrid1_ItemDeleted(ByVal source As ObjectByVal e As Telerik.Web.UI.GridDeletedEventArgs) Handles RadGrid1.ItemDeleted 
' Some code to delete 
End Sub 
 
Private Sub makeCart() 
If IsNothing(Session("Cart"))Then 
objDT = New System.Data.DataTable("Cart"
objDT.Columns.Add("ID"GetType(Integer)) 
objDT.Columns("ID").AutoIncrement = True 
objDT.Columns("ID").AutoIncrementSeed = 1 
objDT.Columns("ID").Unique = True 
objDT.Columns.Add("Quantity"GetType(Integer)) 
objDT.Columns.Add("ProductName"GetType(String)) 
objDT.Columns.Add("ProductID"GetType(Integer)) 
objDT.Columns.Add("Cost"GetType(Decimal)) 
Session("Cart") = objDT 
End Sub 

            <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" GridLines="None" ShowFooter="True" AllowPaging="True" AllowAutomaticDeletes="True" PageSize="20" AllowAutomaticUpdates="True" OnNeedDataSource="RadGrid1_NeedDataSource"
                <PagerStyle Mode="NextPrevAndNumeric" /> 
                <MasterTableView DataKeyNames="ID" HorizontalAlign="NotSet" AutoGenerateColumns="False"
                <Columns> 
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"
                        <ItemStyle CssClass="MyImageButton" /> 
                    </telerik:GridEditCommandColumn>                 
                    <telerik:GridBoundColumn Aggregate="Count" DataField="ID" HeaderText="Product ID" 
                        FooterText="Total products: " UniqueName="ID"
                    </telerik:GridBoundColumn>     
                    <telerik:GridBoundColumn DataField="ProductName" HeaderText="Product name" SortExpression="ProductName" 
                        UniqueName="ProductName"
                    </telerik:GridBoundColumn>      
                    <telerik:GridBoundColumn Aggregate="Sum" DataField="Cost" HeaderText="Unit price" 
                        FooterText="Total unit price: " UniqueName="Cost"
                    </telerik:GridBoundColumn> 
                    <telerik:GridBoundColumn Aggregate="Sum" DataField="Quantity" HeaderText="Qty" 
                        FooterText="All units in stock: " UniqueName="Quantity"
                    </telerik:GridBoundColumn>  
                    <telerik:GridCalculatedColumn HeaderText="Total Price" UniqueName="TotalPrice" DataType="System.Double" 
                        DataFields="Quantity, Cost" Expression="{0}*{1}" FooterText="Total Price: " 
                        Aggregate="Sum" />                                                              
                    <telerik:GridButtonColumn ConfirmText="Delete this product?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" 
                        UniqueName="DeleteColumn"
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /> 
                    </telerik:GridButtonColumn>                      
                </Columns> 
                </MasterTableView> 
                 
            </telerik:RadGrid> 



3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 23 Mar 2009, 09:51 AM
Hi,

Try adding the Event handler for the ItemDeleted event and see whether the ItemDeleted event is getting fired.

ASPX:
 
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" OnItemDeleted="RadGrid1_ItemDeleted" > 
           

Shinu
0
Ching-Yen
Top achievements
Rank 1
answered on 23 Mar 2009, 04:22 PM
Hi,

I tried the suggestion but it still didn't work for me. Do you mind to prepare me a simple test case?

Thanks in advance.
0
Sebastian
Telerik team
answered on 24 Mar 2009, 11:44 AM
Hello Ching-Yen,

I reviewed your code snippets and noticed that you use advanced binding for your grid with NeedDataSource event handling. Automatic data editing operations (AllowAutomaticXXXXX = true) and handling the relevant grid events (ItemUpdated/ItemDeleted/ItemInserted) are supported only when you assing data source controls for grid item generators.

In your case you will need to intercept the DeleteCommand/UpdateCommand/InsertCommand events of the control as shown in the examples below:

http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Ching-Yen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Ching-Yen
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or