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

[Solved] Grid Update Quantity Column in rows

1 Answer 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Byron Lai
Top achievements
Rank 1
Byron Lai asked on 19 Jan 2010, 10:00 PM

I have a datagrid with a quantity column that's updatable on all rows. Each rows is "e.Item.Edit = true;" I use ItemCommand's UpdateAll to get the updated quantity when the user edits those quantity rows. However, they have to click "refresh cart" button to get the update going to execute the ItemCommand. I would like the review button to execute an update of the Cart prior to moving to the next page. When I try to manually trigger the itemCommand w/ "UpdateAll" I get an error because I can't completely emulate the event

I have a datagrid with a quantity column that's updatable on all rows. Each rows is "e.Item.Edit = true;" I use ItemCommand's UpdateAll to get the updated quantity when the user edits those quantity rows. However, they have to click "refresh cart" button to get the update going to execute the ItemCommand. I would like the review button to execute an update of the Cart prior to moving to the next page. When I try to manually trigger the itemCommand w/ "UpdateAll" I get an error because I can't completely emulate the event

grdOrderCart_ItemCommand(object source, GridCommandEventArgs e)

{

case "UpdateAll":

//this.UpdateOrderHeaderFields();

 

//Update Cart

 

DataRow dr;

foreach (GridEditableItem editedItem in grdOrderCart.EditItems)

{

Hashtable newValues = new Hashtable();

//The GridTableView will fill the values from all editable columns in the hash

 

e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

//skip just added items.

 

if (newValues["Quantity"] != null)

{

if (dt.Rows.Find(editedItem.GetDataKeyValue("ItemNo")) != null)

{

dr = dt.Rows.Find(editedItem.GetDataKeyValue("ItemNo"));

dr["Quantity"] = newValues["Quantity"];

dr.AcceptChanges();

}

}

}

}

 

 

 

grdOrderCart_ItemCommand(object source, GridCommandEventArgs e)

{

I have a datagrid with a quantity column that's updatable on all rows. Each rows is "e.Item.Edit = true;" I use ItemCommand's UpdateAll to get the updated quantity when the user edits those quantity rows. However, they have to click "refresh cart" button to get the update going to execute the ItemCommand. I would like the review button to execute an update of the Cart prior to moving to the next page. When I try to manually trigger the itemCommand w/ "UpdateAll" I get an error because I can't completely emulate the event

 

 

//Force Grid into EDIT mode.

 

 

 

 

 

CommandEventArgs eee = new CommandEventArgs("UpdateAll", "Hello");

 

 

GridCommandEventArgs ee = new GridCommandEventArgs(null, "UpdateAll", eee);

 

grdOrderCart_ItemCommand(grdOrderCart, ee);

grdOrderCart.Rebind();

 

 

 

 

protected void grdOrderCart_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

DataTable dt = dsDSD.Tables[B2B.DSD.Tables.OrderCart];

 

dt.PrimaryKey =

new DataColumn[] { dt.Columns["ItemNo"] };

 

 

switch (e.CommandName)

 

{

 

case "Delete":

 

 

string itemNo = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ItemNo"].ToString();

 

 

string desc = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Description"].ToString();

 

 

if (dt.Rows.Find(itemNo) != null)

 

{

dt.Rows.Find(itemNo).Delete();

lblMessages.Text +=

string.Format("<br>Deleted: {0} - {1}", itemNo, desc);

 

dt.AcceptChanges();

}

 

break;

 

 

case "UpdateAll":

 

 

//this.UpdateOrderHeaderFields();

 

 

 

 

 

//Update Cart

 

 

 

 

 

DataRow dr;

 

 

foreach (GridEditableItem editedItem in grdOrderCart.EditItems)

 

{

 

Hashtable newValues = new Hashtable();

 

 

//The GridTableView will fill the values from all editable columns in the hash

 

 

 

 

e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

 

//skip just added items.

 

 

 

 

 

if (newValues["Quantity"] != null)

 

{

 

if (dt.Rows.Find(editedItem.GetDataKeyValue("ItemNo")) != null)

 

{

dr = dt.Rows.Find(editedItem.GetDataKeyValue(

"ItemNo"));

 

dr[

"Quantity"] = newValues["Quantity"];

 

dr.AcceptChanges();

}

}

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Jan 2010, 07:32 AM
Hi,

You can trigger the UpdateAll command of the RadGrid using the FireCommandEvent  from the the Review Order button

C#:
protected void btnReviewOrder_Click(object sender, EventArgs e)  
    {  
        GridDataItem item = (GridDataItem) RadGrid1.MasterTableView.Items[0];  
        item.FireCommandEvent("UpdateAll", String.Empty);  
    }  
    protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
    {  
       if(e.CommandName=="UpdateAll")  
       {  
       }  
    }  


Thanks,
Shinu
Tags
Grid
Asked by
Byron Lai
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or