I have a page with a RadGrid on it that I've been testing with. I do not have any kind of DataSource control on it, so I am manually wiring up a datasource to it on the NeedDataEvent and then, of course, wiring up the various command item events. I had my test page all working with insert, update, and delete events until... I changed several columns from simple GridBoundColumn columns to GridTemplateColumn columns.
Using the GridBoundColumn type, the following code worked just fine:
The code line of interest is inside the try block where it calls the editItem.UpdateValues method. And it is this line that no longer seems to work if my columns are of the GridTemplateColumn type. There is is no error that is thrown, it's just the row (a DataRow object) is not updated with new values from any template columns, only bound columns.
In both cases, I have the MasterTableView setup with "EditMode="EditForms", the only change is in the markup.
for the bound column, I had this:
for the template column, I had this:
So when changing to the template column, I find that I can code something like
and of course work on manually updating my DataRow object accordingly. But... I'm trying to *understand* this, and quite frankly I'm not finding much documentation on it.
So... could someone provide me pointers to documentation on the differences between Template and Bound columns? Or even some more reference material on the ExtractValues, UpdateValues methods?
I realize I can work on coding up a scenario where I use the .FindControl method for every column I'm interested in, but I guess I'm after a little more education...
Any help would be greatly appreciated. Thanks in advance.
Using the GridBoundColumn type, the following code worked just fine:
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) |
{ |
DataTable dt = GridSource; |
GridEditableItem eeditItem = e.Item as GridEditableItem; |
int rowkey = (int?)editItem.GetDataKeyValue(IDColumnName) ?? 0; |
DataRow row = dt.Rows.Find(rowkey); |
if (row != null) |
{ |
row.BeginEdit(); |
try |
{ |
editItem.UpdateValues(row); |
row["EditAction"] = "update"; |
row.EndEdit(); |
TrackChange(rowkey, "update"); |
} |
catch (Exception ex) |
{ |
row.CancelEdit(); |
RadGrid1.Controls.Add(new LiteralControl("Unable to update record: " + ex.Message)); |
e.Canceled = true; |
} |
} |
txtCommandInfo.Text = String.Format("ItemIndex {0} rowkey {1}", e.Item.ItemIndex.ToString(), rowkey); |
} |
The code line of interest is inside the try block where it calls the editItem.UpdateValues method. And it is this line that no longer seems to work if my columns are of the GridTemplateColumn type. There is is no error that is thrown, it's just the row (a DataRow object) is not updated with new values from any template columns, only bound columns.
In both cases, I have the MasterTableView setup with "EditMode="EditForms", the only change is in the markup.
for the bound column, I had this:
<telerik:GridBoundColumn HeaderText="FirstName" DataField="FirstName" UniqueName="FirstName" |
MaxLength="20" /> |
for the template column, I had this:
<telerik:GridTemplateColumn HeaderText="FirstName" UniqueName="FirstNameTemplate"> |
<ItemTemplate> |
<%# Eval("FirstName") %> |
</ItemTemplate> |
<EditItemTemplate> |
<asp:TextBox ID="FirstName" runat="server" Text='<%# Eval("FirstName") %>' /> |
<asp:RequiredFieldValidator ID="rfvFirstName" runat="server" ErrorMessage="First name is required." |
ControlToValidate="FirstName"></asp:RequiredFieldValidator> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
So when changing to the template column, I find that I can code something like
string txt; |
TextBox ctrl = (TextBox)editItem.FindControl("FirstName"); |
if (ctrl != null) |
txt = ctrl.Text; |
and of course work on manually updating my DataRow object accordingly. But... I'm trying to *understand* this, and quite frankly I'm not finding much documentation on it.
So... could someone provide me pointers to documentation on the differences between Template and Bound columns? Or even some more reference material on the ExtractValues, UpdateValues methods?
I realize I can work on coding up a scenario where I use the .FindControl method for every column I'm interested in, but I guess I'm after a little more education...
Any help would be greatly appreciated. Thanks in advance.