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

Grid Issue with Regular Expression and ExtractValuesFromItem Issue

1 Answer 207 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SchaF
Top achievements
Rank 1
SchaF asked on 27 Jun 2013, 04:28 PM
I have a grid where on the ItemDataBound event, Im using some custom checking on the columns based on a list of objects from my database to see if the column can be edited or not. For the ones that can be edited, I then created a RegularExpressionValidator for the table cell along with setting the maxlength of the textbox when its in edit mode. This works perfectly until when I go to update the record. The way Im doing it is to grab the edited cell, build a gridRow and then remove that currently selected GridRow (the one being edited) and insert the new one using the new values from the edited row.

Here is my regular expression building
GridEditableItem item = e.Item as GridEditableItem;
 
//this is within a loop for the columns and another loop for my custom objects (metaData)
//set edit textbox max length
item[column.UniqueName].Enabled = true;
TextBox txtbx = (TextBox)item[column.UniqueName].Controls[0];
txtbx.MaxLength = metaData.MaxFieldLength;
 
//set regular expression for validation
RegularExpressionValidator regex = new RegularExpressionValidator();
GridTextBoxColumnEditor editor = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor(column.UniqueName);
TableCell cell = (TableCell)editor.TextBoxControl.Parent;
 
editor.TextBoxControl.ID = "Validation" + column.UniqueName;
 
regex.Display = ValidatorDisplay.Dynamic;
regex.ControlToValidate = editor.TextBoxControl.ID;
regex.ForeColor = System.Drawing.Color.Red;
regex.ValidationExpression = @"^";
//custom regex expression building
regex.ValidationExpression = regex.ValidationExpression + @"$";
 
cell.Controls.Add(regex);


I get this values by during my grid_UpdateCommand event and call
//get selected row
GridEditableItem item = (GridEditableItem)e.Item;
//get values from the row
Hashtable newValues = new Hashtable();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, item);


The row Im dealing with is working weird because during this call, the 2 columns textboxes that arent enabled (think like ReadOnly but the user can still see the values) are getting the new record values fine, but the 2 user editable textboxes are pulling back a null. When I turn the regular expression building off (comment it out), it pulls the records perfectly with all the column values. But when I have the regular expression building and checking on, it cant pull these values? Any reason why?

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 02 Jul 2013, 11:04 AM
Hello Brandon,

The problem is probably caused by the fact that the logic is executed in the OnItemDataBound event. Please try moving the logic in the OnItemCreated event. When using the data bound event and adding controls in the controls collection they will not persist in the ViewState and may lead to unexpected behavior. If this does not help please show us your entire markup and code-behind so we could investigate further.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
SchaF
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or