Hi guys,
I am doing manual updates/inserts on the RadGrid using OnUpdateCommand event.
I am using a EditForm template to achieve this.
Now, I have several columns coming as part of a select statement in a Stored proc; which returns a DataTable, which then forms the DataSource of the grid.
Many of these columns are not being used while editing. For instance if 10 columns are coming in, I am editing only 5.
In the OnUpdateCommand event, I am able to get hold of the items on the EditForm, using the following code:
protected void RadGrid_Bank_UpdateCommand(object sender, GridCommandEventArgs e)
{
RadGrid grid = (RadGrid)sender;
int itemIndex = e.Item.ItemIndex;
GridEditableItem editedItem = e.Item as GridEditableItem;
GridNestedViewItem nestedEditForm = grid.MasterTableView.Items[itemIndex].ChildItem;
RadComboBox accUsageTypeEditor = (RadComboBox)editedItem.FindControl("accUsageTypeEditor");
RadDatePicker effBankDateEditor = (RadDatePicker)editedItem.FindControl("effBankDateEditor");
RadDatePicker effToBankDateEditor = (RadDatePicker)editedItem.FindControl("effToBankDateEditor");
// So now, get the corresponding value from the editors
string s = accUsageTypeEditor.SelectedValue;
}
But I have not been able to get hold of the other columns which are not a part of my EditForm. Is there any way I can hold of the current DataRow object or a DataSource object from which the row could be extracted using the ItemIndex??
Regards,
I am doing manual updates/inserts on the RadGrid using OnUpdateCommand event.
I am using a EditForm template to achieve this.
Now, I have several columns coming as part of a select statement in a Stored proc; which returns a DataTable, which then forms the DataSource of the grid.
Many of these columns are not being used while editing. For instance if 10 columns are coming in, I am editing only 5.
In the OnUpdateCommand event, I am able to get hold of the items on the EditForm, using the following code:
protected void RadGrid_Bank_UpdateCommand(object sender, GridCommandEventArgs e)
{
RadGrid grid = (RadGrid)sender;
int itemIndex = e.Item.ItemIndex;
GridEditableItem editedItem = e.Item as GridEditableItem;
GridNestedViewItem nestedEditForm = grid.MasterTableView.Items[itemIndex].ChildItem;
RadComboBox accUsageTypeEditor = (RadComboBox)editedItem.FindControl("accUsageTypeEditor");
RadDatePicker effBankDateEditor = (RadDatePicker)editedItem.FindControl("effBankDateEditor");
RadDatePicker effToBankDateEditor = (RadDatePicker)editedItem.FindControl("effToBankDateEditor");
// So now, get the corresponding value from the editors
string s = accUsageTypeEditor.SelectedValue;
}
But I have not been able to get hold of the other columns which are not a part of my EditForm. Is there any way I can hold of the current DataRow object or a DataSource object from which the row could be extracted using the ItemIndex??
Regards,
6 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 20 May 2008, 06:08 AM
Hi,
Try setting the DataKeyNames Property for the RadGrid and access the readonly column in the UpdateCommand as shown below.
ASPX:
| <MasterTableView DataKeyNames="ProductName" Name="Master" > |
CS:
| protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditableItem editedItem = (GridEditableItem)e.Item; |
| //Get the readonly field using the DataKeyValue. |
| string productname= editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ProductName"].ToString(); |
| } |
Princy.
0
Siddharth
Top achievements
Rank 1
answered on 20 May 2008, 06:19 AM
Hi Princy,
I understand what you saying. But what if the unused column is not a part of the DataKey ? For example, I can have columns like : ProductId, CatalogId, ProdName, ProdCategory, ShippedDate, ProductInStock (bool).
In this case, my DataKeyNames will be "ProductId, CatalogId" because that represents a unique combination (composite key). I also want the user to edit
ProdName, ProdCategory, ShippedDate, but I dont want him to know whether ProductInStock or not and neither I want him to edit this column.
(This is just a hypothetical situation, in my scenario, there are heaps of columns like this). So ProductInStock does not form a part of the EditForm template.
So how do I get hold of these columns while in UpdateCommand ?
I understand what you saying. But what if the unused column is not a part of the DataKey ? For example, I can have columns like : ProductId, CatalogId, ProdName, ProdCategory, ShippedDate, ProductInStock (bool).
In this case, my DataKeyNames will be "ProductId, CatalogId" because that represents a unique combination (composite key). I also want the user to edit
ProdName, ProdCategory, ShippedDate, but I dont want him to know whether ProductInStock or not and neither I want him to edit this column.
(This is just a hypothetical situation, in my scenario, there are heaps of columns like this). So ProductInStock does not form a part of the EditForm template.
So how do I get hold of these columns while in UpdateCommand ?
0
Siddharth
Top achievements
Rank 1
answered on 21 May 2008, 02:21 AM
Anyone got an answer to this yet ?
Telerik guru's ?
Telerik guru's ?
0
Hello Siddharth,
I suggest you add columns to your grid for the fields that you need to access on UpdateCommand, but set the Display and the ReadOnly properties for these columns to false. Thus the columns won't be visible or editable and you would be able to get there values when needed. For instance:
Let us know if this helps.
Regards,
Iana
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I suggest you add columns to your grid for the fields that you need to access on UpdateCommand, but set the Display and the ReadOnly properties for these columns to false. Thus the columns won't be visible or editable and you would be able to get there values when needed. For instance:
| <telerik:GridBoundColumn DataField="ProductInStock" HeaderText="ProductInStock" |
| UniqueName="ProductInStock" Display="false" ReadOnly="true"> |
| </telerik:GridBoundColumn> |
| protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditFormItem item = e.Item as GridEditFormItem; |
| string productInStock = item.ParentItem["ProductInStock"].Text; |
| } |
Let us know if this helps.
Regards,
Iana
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0
Siddharth
Top achievements
Rank 1
answered on 23 May 2008, 01:41 AM
Hi Iana,
What column type to use when you need to display Timestamp value on the grid. I am using Sybase as my back-end and the timestamp value gets rendered as "System.Byte[]" on the page instead of some hex value.
So, when I add the timestamp as a column to the grid and access the timestamp value the way you suggested, I get a string value of "System.Byte[]" instead of the actual value. How to overcome this?
Regards,
What column type to use when you need to display Timestamp value on the grid. I am using Sybase as my back-end and the timestamp value gets rendered as "System.Byte[]" on the page instead of some hex value.
So, when I add the timestamp as a column to the grid and access the timestamp value the way you suggested, I get a string value of "System.Byte[]" instead of the actual value. How to overcome this?
Regards,
0
Hello Siddharth,
I suggest that you use another stored procedure to select the needed data from the database and access it on UpdateCommand in your case. You could use the grid DataKeyNames to fill the parameters for the where clause of the sql query and DataReader to get the timestamp value.
Use the following code snippet to get the DataKeyNames for the current edited item on UpdateCommand:
I hope this helps!
All the best,
Iana
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
I suggest that you use another stored procedure to select the needed data from the database and access it on UpdateCommand in your case. You could use the grid DataKeyNames to fill the parameters for the where clause of the sql query and DataReader to get the timestamp value.
Use the following code snippet to get the DataKeyNames for the current edited item on UpdateCommand:
| string keyValue = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"]; |
I hope this helps!
All the best,
Iana
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center