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

Update with class.

2 Answers 47 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 18 Oct 2012, 04:07 PM
I need to check for customer pricing and or volume pricing before updating grid. Why does this not work?

protected void RadCartGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            GridEditableItem editedItem = e.Item as GridEditableItem;
            
            string itemNumber = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Itemnumber"].ToString();
            int lineID = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["LineID"].ToString());
            string custNum = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["CustomerNumber"].ToString();
            int qty = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Quantity"].ToString());
           
            //CHECK FOR CUSTOMER PRICING OR QTY BREAK PRICING.
            updateCart.UPDateItem(itemNumber, lineID, custNum, qty);
            RadCartGrid1.Rebind();
        }

2 Answers, 1 is accepted

Sort by
0
Nick
Top achievements
Rank 1
answered on 18 Oct 2012, 05:14 PM
Silly me... I forgot to include to the DataKeyNames the 'Quantity'
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Oct 2012, 05:16 PM
Hello,

Please check below demo

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
      OnUpdateCommand="RadGrid1_UpdateCommand"
>
            <MasterTableView CommandItemDisplay="Top" DataKeyNames="ID,Name">
                <Columns>
                    <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
                        </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            dynamic data = new[] {
              new { ID = 1, Name ="aaa"},
              new { ID = 2, Name = "bbb"},
              new { ID = 3, Name = "ccc"},
              new { ID = 4, Name = "ddd"},
               new { ID = 5, Name ="eee"},
               new { ID = 6, Name ="aaa"},
              new { ID = 7, Name = "bbb"},
              new { ID = 8, Name = "ccc"},
              new { ID = 9, Name = "ddd"},
               new { ID = 10, Name ="eee"}
            };
            RadGrid1.DataSource = data;
        }
 
 
      protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
        {
            // Perform your Update Logic here
            GridEditableItem item = e.Item as GridEditableItem;
 
            // Get Old Value
 
            string strId = item.GetDataKeyValue("ID").ToString();
            string strName = item.GetDataKeyValue("Name").ToString();
 
            // Get New Value
            // Bound COlumn
            string strNewId = (item["ID"].Controls[0] as TextBox).Text;
            //Template Column
            string strNewName = (item.FindControl("TextBox1") as TextBox).Text;
 
            // Perform Your DB opertaion
 
            // No need to write below line - radgrid manage it automatically
            //RadGrid1.Rebind();
        }



Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Nick
Top achievements
Rank 1
Answers by
Nick
Top achievements
Rank 1
Jayesh Goyani
Top achievements
Rank 2
Share this question
or