I followed the .NET 3.5 - LinqToSql Manual CRUD Operations to implement a quick add/update functionality to my manual Manager Screen. The example uses NumericTextBoxSetting to show how validation is being handled etc. My requirement has mostly to do with text and phone numbers with RegExp patterns.
What happens is that in runtime, if there is invalid data in fileds, the scree just flickers. No error/empty messages appear. No icon appears.
Also, I have one GridDropDownColumn. How am I to extract its value while Inserting or updating?
The RadGrid and it's RadInputManager:
The code-behind relating to the InputManager:
The code-behind relating to the RadGrid:
I'm missing something here right? Have I hooked up everything right? This is a Content Page and the ShowErrorMessage() first traces-out the parent's WindowManager.
Any pointer please... this was suppose to be a simple screen and I have like 7 others to do today. Thank you.
*EDIT*
Also, using Firefox + FireBug, I see a warning whenever I interact with the grid I mentioned above. Attached.
What happens is that in runtime, if there is invalid data in fileds, the scree just flickers. No error/empty messages appear. No icon appears.
Also, I have one GridDropDownColumn. How am I to extract its value while Inserting or updating?
The RadGrid and it's RadInputManager:
<
fieldset
id
=
"fieldGrid"
style
=
"width: 870px"
>
<
legend
>Managers</
legend
>
<
telerik:RadGrid
ID
=
"RadGridManagers"
runat
=
"server"
AutoGenerateColumns
=
"False"
AllowPaging
=
"True"
GridLines
=
"None"
Width
=
"100%"
Skin
=
"Office2007"
SkinID
=
"RadGrid_UnPageable"
PageSize
=
"20"
OnNeedDataSource
=
"RadGridManagers_NeedDataSource"
OnItemCreated
=
"RadGridManagers_ItemCreated"
OnInsertCommand
=
"RadGridManagers_InsertCommand"
OnUpdateCommand
=
"RadGridManagers_UpdateCommand"
DataSourceID
=
"LinqDataSourceManagers"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
CommandItemDisplay
=
"Top"
Width
=
"100%"
DataSourceID
=
"LinqDataSourceManagers"
DataKeyNames
=
"OID"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"ColumnEditCommand"
ItemStyle-CssClass
=
"MyImageButton"
/>
<
telerik:GridBoundColumn
DataField
=
"FirstName"
HeaderText
=
"First Name"
UniqueName
=
"ColumnFirstName"
Visible
=
"false"
/>
<
telerik:GridBoundColumn
DataField
=
"LastName"
HeaderText
=
"Last Name"
UniqueName
=
"ColumnLastName"
Visible
=
"false"
/>
<
telerik:GridTemplateColumn
HeaderText
=
"Name"
UniqueName
=
"columnName"
ReadOnly
=
"true"
>
<
ItemTemplate
>
<%# string.Format("{0} {1}", Eval("FirstName"), Eval("LastName"))%>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"NickName"
HeaderText
=
"Nick Name"
UniqueName
=
"ColumnNickName"
/>
<
telerik:GridDropDownColumn
DataField
=
"OID"
HeaderText
=
"Pharmacy"
UniqueName
=
"ColumnPharmacy"
DataSourceID
=
"LinqDataSourcePharmacies"
ListValueField
=
"OID"
ListTextField
=
"Name"
ColumnEditorID
=
"GridDropDownColumnEditorPharmacy"
/>
<
telerik:GridBoundColumn
DataField
=
"PhoneNumber"
HeaderText
=
"Phone #"
UniqueName
=
"ColumnPhoneNumber"
/>
<
telerik:GridBoundColumn
DataField
=
"MobileNumber"
HeaderText
=
"Mobile #"
UniqueName
=
"ColumnMobileNumber"
/>
<
telerik:GridBoundColumn
DataField
=
"Email"
HeaderText
=
"Email Address"
UniqueName
=
"ColumnEmail"
/>
<%--
<
telerik:GridButtonColumn
ConfirmText
=
"Delete this manager?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"ColumnDelete"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
/>
</
telerik:GridButtonColumn
>
--%>
</
Columns
>
<
EditFormSettings
CaptionDataField
=
"FirstName"
CaptionFormatString
=
"Edit Manager {0}"
>
<
EditColumn
ButtonType
=
"ImageButton"
UniqueName
=
"ColumnEditCommandE"
/>
<
FormTableItemStyle
Wrap
=
"False"
/>
<
FormCaptionStyle
CssClass
=
"EditFormHeader"
/>
<
FormMainTableStyle
GridLines
=
"None"
CellSpacing
=
"0"
CellPadding
=
"3"
BackColor
=
"White"
Width
=
"100%"
/>
<
FormTableStyle
CellSpacing
=
"0"
CellPadding
=
"2"
Height
=
"110px"
BackColor
=
"White"
/>
<
FormTableAlternatingItemStyle
Wrap
=
"False"
/>
<
FormTableButtonRowStyle
/>
</
EditFormSettings
>
<
CommandItemSettings
ShowRefreshButton
=
"true"
ShowAddNewRecordButton
=
"true"
ShowExportToWordButton
=
"false"
ShowExportToExcelButton
=
"true"
ShowExportToPdfButton
=
"true"
ShowExportToCsvButton
=
"true"
/>
<
PagerStyle
AlwaysVisible
=
"true"
Mode
=
"NextPrevAndNumeric"
Position
=
"Bottom"
/>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowDblClick
=
"RadGridManagers_OnRowDblClick"
/>
<
Scrolling
UseStaticHeaders
=
"True"
/>
</
ClientSettings
>
<
ExportSettings
HideStructureColumns
=
"false"
FileName
=
"PharmacyManagers"
IgnorePaging
=
"True"
>
<
Excel
Format
=
"ExcelML"
/>
<
Csv
ColumnDelimiter
=
"VerticalBar"
/>
</
ExportSettings
>
</
telerik:RadGrid
>
<
telerik:GridDropDownListColumnEditor
ID
=
"GridDropDownColumnEditorPharmacy"
runat
=
"server"
DropDownStyle-Width
=
"228px"
/>
<
telerik:RadInputManager
runat
=
"server"
ID
=
"RadInputManagerManagers"
Enabled
=
"true"
>
<
telerik:TextBoxSetting
BehaviorID
=
"TextBoxSettingNameFirst"
EmptyMessage
=
"Please enter a first name"
/>
<
telerik:TextBoxSetting
BehaviorID
=
"TextBoxSettingNameLast"
EmptyMessage
=
"Please enter a last name"
/>
<
telerik:TextBoxSetting
BehaviorID
=
"TextBoxSettingNameNick"
EmptyMessage
=
"Please enter a nick name"
/>
<
telerik:RegExpTextBoxSetting
BehaviorID
=
"RegExpTextBoxSettingPhone"
ErrorMessage
=
"Invalid U.K. Phone Number"
ValidationExpression
=
"^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$ "
/>
<
telerik:RegExpTextBoxSetting
BehaviorID
=
"RegExpTextBoxSettingMobile"
ErrorMessage
=
"Invalid U.K. Mobile Number"
ValidationExpression
=
"^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$"
/>
<
telerik:RegExpTextBoxSetting
BehaviorID
=
"RegExpTextBoxSettingEmail"
ErrorMessage
=
"Enter a valid email address"
ValidationExpression
=
"^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$"
/>
</
telerik:RadInputManager
>
</
fieldset
>
The code-behind relating to the InputManager:
private
void
ShowErrorMessage() {
RadAjaxManager manager = RadAjaxManager.GetCurrent(
this
.Page);
manager.ResponseScripts.Add(
"window.radalert(\"Please enter valid data!\")"
);
}
private
void
SetupInputManager(GridEditableItem editableItem) {
InputSetting inputSetting;
// style first name
var textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor(
"ColumnFirstName"
)).TextBoxControl;
textBox.ID =
"TextBoxFirstName"
;
inputSetting = RadInputManagerManagers.GetSettingByBehaviorID(
"TextBoxSettingNameFirst"
);
inputSetting.InitializeOnClient =
true
;
inputSetting.TargetControls.Add(
new
TargetInput(textBox.UniqueID,
true
));
inputSetting.Validation.IsRequired =
true
;
// style last name
textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor(
"ColumnLastName"
)).TextBoxControl;
textBox.ID =
"TextBoxLastName"
;
inputSetting = RadInputManagerManagers.GetSettingByBehaviorID(
"TextBoxSettingNameLast"
);
inputSetting.InitializeOnClient =
true
;
inputSetting.TargetControls.Add(
new
TargetInput(textBox.UniqueID,
true
));
inputSetting.Validation.IsRequired =
true
;
// style nick name
textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor(
"ColumnNickName"
)).TextBoxControl;
textBox.ID =
"TextBoxNickName"
;
inputSetting = RadInputManagerManagers.GetSettingByBehaviorID(
"TextBoxSettingNameNick"
);
inputSetting.InitializeOnClient =
true
;
inputSetting.TargetControls.Add(
new
TargetInput(textBox.UniqueID,
true
));
// style phone number
textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor(
"ColumnPhoneNumber"
)).TextBoxControl;
textBox.ID =
"TextBoxPhoneNumber"
;
inputSetting = RadInputManagerManagers.GetSettingByBehaviorID(
"RegExpTextBoxSettingPhone"
);
inputSetting.InitializeOnClient =
true
;
inputSetting.TargetControls.Add(
new
TargetInput(textBox.UniqueID,
true
));
// style mobile number
textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor(
"ColumnMobileNumber"
)).TextBoxControl;
textBox.ID =
"TextBoxMobileNumber"
;
inputSetting = RadInputManagerManagers.GetSettingByBehaviorID(
"RegExpTextBoxSettingMobile"
);
inputSetting.InitializeOnClient =
true
;
inputSetting.TargetControls.Add(
new
TargetInput(textBox.UniqueID,
true
));
// style email
textBox = ((GridTextBoxColumnEditor)editableItem.EditManager.GetColumnEditor(
"ColumnMobileNumber"
)).TextBoxControl;
textBox.ID =
"TextBoxEmail"
;
inputSetting = RadInputManagerManagers.GetSettingByBehaviorID(
"RegExpTextBoxSettingEmail"
);
inputSetting.InitializeOnClient =
true
;
inputSetting.TargetControls.Add(
new
TargetInput(textBox.UniqueID,
true
));
}
The code-behind relating to the RadGrid:
#region Grid Related
protected
void
RadGridManagers_NeedDataSource(
object
source, GridNeedDataSourceEventArgs e) {
RadGridManagers.DataSource = LinqDataSourceManagers;
}
protected
void
RadGridManagers_ItemCreated(
object
sender, GridItemEventArgs e) {
if
(e.Item
is
GridEditableItem && (e.Item.IsInEditMode)) {
GridEditableItem editableItem = (GridEditableItem)e.Item;
SetupInputManager(editableItem);
}
}
protected
void
RadGridManagers_UpdateCommand(
object
source, GridCommandEventArgs e) {
var editableItem = ((GridEditableItem)e.Item);
var editManagerID = (
long
)editableItem.GetDataKeyValue(
"OID"
);
//retrieve entity form the Db
var editManager = DbContext.Managers.Where(maan => maan.OID == editManagerID).FirstOrDefault();
if
(editManager !=
null
) {
try
{
//update entity's state
editableItem.UpdateValues(editManager);
//submit changes to Db
DbContext.SubmitChanges();
}
catch
(Exception) {
ShowErrorMessage();
}
}
}
protected
void
RadGridManagers_InsertCommand(
object
source, GridCommandEventArgs e) {
var editableItem = ((GridEditableItem)e.Item);
//extract properties
Hashtable values =
new
Hashtable( );
editableItem.ExtractValues(values);
//create new entity
Manager newManager =
new
Manager() {
FirstName = (
string
)values[
"FirstName"
] ?? String.Empty,
LastName = (
string
)values[
"LastName"
] ?? String.Empty,
NickName = (
string
)values[
"NickName"
] ?? String.Empty,
PhoneNumber = (
string
)values[
"PhoneNumber"
] ?? String.Empty,
MobileNumber = (
string
)values[
"MobileNumber"
] ?? String.Empty,
Email = (
string
)values[
"Email"
] ?? String.Empty
};
DbContext.Managers.InsertOnSubmit(newManager);
try
{
//submit changes to Db
DbContext.SubmitChanges();
}
catch
(Exception) {
ShowErrorMessage();
}
}
#endregion
I'm missing something here right? Have I hooked up everything right? This is a Content Page and the ShowErrorMessage() first traces-out the parent's WindowManager.
Any pointer please... this was suppose to be a simple screen and I have like 7 others to do today. Thank you.
*EDIT*
Also, using Firefox + FireBug, I see a warning whenever I interact with the grid I mentioned above. Attached.