Here is the ASPX code:
<
telerik:RadGrid
ID
=
"gvEditProjectPositions"
Width
=
"99.8%"
AllowMultiRowEdit
=
"False"
AllowAutomaticDeleteCommand
=
"false"
Skin
=
"Metro"
runat
=
"server"
EnableLinqExpressions
=
"False"
GridLines
=
"None"
AutoGenerateColumns
=
"False"
>
<
MasterTableView
Width
=
"100%"
DataKeyNames
=
"ProjectPositionID"
CommandItemDisplay
=
"Top"
EnableColumnsViewState
=
"False"
EditMode
=
"Batch"
>
<
CommandItemSettings
SaveChangesText
=
"Save to Grid"
ShowCancelChangesButton
=
"False"
ShowRefreshButton
=
"False"
/>
<
BatchEditingSettings
EditType
=
"Row"
OpenEditingEvent
=
"mousedown"
/>
<
Columns
>
<
telerik:GridButtonColumn
HeaderStyle-Width
=
"32px"
ConfirmText
=
"Delete this position?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
ConfirmDialogHeight
=
"160px"
ConfirmDialogWidth
=
"250px"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridButtonColumn
>
<
telerik:GridBoundColumn
DataField
=
"ProjectPositionID"
HeaderText
=
"ID"
UniqueName
=
"ProjectPositionID"
Display
=
"False"
/>
<
telerik:GridTemplateColumn
DataField
=
"PositionName"
HeaderStyle-Width
=
"170px"
HeaderText
=
"Position Name"
UniqueName
=
"PositionName"
>
<
ItemTemplate
>
<%# Eval("PositionName")%>
</
ItemTemplate
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
<
EditItemTemplate
>
<
asp:TextBox
runat
=
"server"
ID
=
"txtEditPositionName"
MaxLength
=
"100"
Width
=
"150px"
CssClass
=
"marginFix"
></
asp:TextBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Staff - Unloaded Rate"
HeaderStyle-Width
=
"215px"
UniqueName
=
"Staff"
DataField
=
"StaffMemberID"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblEditProjectPositionStaff"
runat
=
"server"
/>
</
ItemTemplate
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
<
EditItemTemplate
>
<
asp:ObjectDataSource
ID
=
"StaffDataSource"
TypeName
=
"ResourcePlanner.service.StaffService"
SelectMethod
=
"GetActiveStaff"
runat
=
"server"
></
asp:ObjectDataSource
>
<
telerik:RadDropDownList
ID
=
"rddlStaff"
runat
=
"server"
DataSourceID
=
"StaffDataSource"
SelectedValue
=
"StaffMemberID"
DataValueField
=
"StaffMemberID"
DataTextField
=
"NameRate"
Width
=
"205"
AutoPostBack
=
"True"
>
</
telerik:RadDropDownList
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
DataField
=
"LoadedRate"
HeaderText
=
"Loaded Rate"
UniqueName
=
"LoadedRate"
>
<
ItemTemplate
>
<%# Eval("LoadedRate", "{0:0.00}")%>
</
ItemTemplate
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
<
EditItemTemplate
>
<
telerik:RadNumericTextBox
ID
=
"txtEditLoadedRate"
NumberFormat
=
"{0:0.00}"
DataType
=
"System.Decimal"
CssClass
=
"tel-num-short-box"
runat
=
"server"
/>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours1Hours"
HeaderText
=
"Month 1"
UniqueName
=
"Month_1"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours2Hours"
HeaderText
=
"Month 2"
UniqueName
=
"Month_2"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours3Hours"
HeaderText
=
"Month 3"
UniqueName
=
"Month_3"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours4Hours"
HeaderText
=
"Month 4"
UniqueName
=
"Month_4"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours5Hours"
HeaderText
=
"Month 5"
UniqueName
=
"Month_5"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours6Hours"
HeaderText
=
"Month 6"
UniqueName
=
"Month_6"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours7Hours"
HeaderText
=
"Month 7"
UniqueName
=
"Month_7"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours8Hours"
HeaderText
=
"Month 8"
UniqueName
=
"Month_8"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
<
telerik:GridNumericColumn
DataField
=
"PositionHours9Hours"
HeaderText
=
"Month 9"
UniqueName
=
"Month_9"
ItemStyle-CssClass
=
"tel-num-short-box"
DecimalDigits
=
"0"
MaxLength
=
"3"
>
<
ItemStyle
HorizontalAlign
=
"Right"
/>
</
telerik:GridNumericColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
Here is the code behind:
Private
Sub
gvEditProjectPositions_BatchEditCommand(sender
As
Object
, e
As
GridBatchEditingEventArgs)
Handles
gvEditProjectPositions.BatchEditCommand
Dim
bSavedSuccessfully
As
Boolean
=
False
Dim
newValues
As
Hashtable
Dim
oldValues
As
Hashtable
Try
Dim
staffInfo
As
List(Of domain.Staff) = StaffService.GetActiveStaff()
For
Each
command
As
GridBatchEditingCommand
In
e.Commands
'Ignore delete commands, we don't need to verify these.
If
(command.Type <> GridBatchEditingCommandType.Delete)
Then
newValues = command.NewValues
oldValues = command.OldValues
Dim
countErrors
As
Integer
'Loop through and make sure the positionname is not null or nothing and that the user is active.
countErrors = projectDetail.Positions.Where(
Function
(p)
String
.IsNullOrEmpty(newValues(
"PositionName"
))
And
(p.IsActive =
"T"
)).Count
If
countErrors > 0
Then
ScriptManager.RegisterStartupScript(
Me
,
Me
.
GetType
(),
"showErrorMessage"
,
"showErrorMessage('Position Name cannot be left blank.');"
,
True
)
Exit
Sub
End
If
'Loop through and check for duplicate staff members, ignoring unassigned staffmembers, and ignoring the currently edited row.
If
(
String
.IsNullOrEmpty(newValues(
"StaffMemberID"
)))
Then
'newValues("StaffMemberID") = "0"
End
If
countErrors = projectDetail.Positions.Where(
Function
(p)
CLng
(newValues(
"StaffMemberID"
)) <> 0
And
p.StaffMemberID =
CLng
(newValues(
"StaffMemberID"
))
And
CLng
(newValues(
"ProjecID"
)) <> p.ProjectID).Count
If
(countErrors > 0)
Then
ScriptManager.RegisterStartupScript(
Me
,
Me
.
GetType
(),
"showErrorMessage"
,
"showErrorMessage('Staff Members can only appear once within a grid.');"
,
True
)
Exit
Sub
End
If
End
If
Next
'dim projectService as new ProjectsService(Master.clsCU.UserId)
For
Each
command
As
GridBatchEditingCommand
In
e.Commands
Dim
projectPosition
As
domain.ProjectPosition
newValues = command.NewValues
oldValues = command.OldValues
Dim
positionId
As
Long
= newValues(
"ProjectPositionID"
)
Dim
projectPositionService
As
New
ProjectPositionService(Master.clsCU.UserId)
If
(command.Type = GridBatchEditingCommandType.Delete)
Then
'Delete the specified project position.
projectPosition = projectDetail.Positions.FirstOrDefault(
Function
(p) p.ProjectPositionID = positionId)
projectPosition.ProjectID = projectDetail.ProjectID
projectPositionService.Delete(projectPosition)
ElseIf
(command.Type = GridBatchEditingCommandType.Update)
Then
'Update the specified Project
projectPosition = projectPositionService.GetProjectPositionById(positionId)
FillPositionFromHashtable(projectPosition, newValues)
'projectPosition.Project = projectDetail
projectPositionService.Update(projectPosition)
For
Each
pph
In
projectPosition.ProjectPositionHours
Dim
pphs
As
New
ProjectPositionHoursService(Master.clsCU.UserId)
pph.ProjectPositionID = positionId
If
pph.ProjectPositionHoursID > 3000
Then
pphs.Update(pph)
End
If
Next
ElseIf
(command.Type = GridBatchEditingCommandType.Insert)
Then
'Add a new project, with these details.
projectPosition =
New
ProjectPosition()
FillPositionFromHashtable(projectPosition, newValues)
projectPosition.ProjectID = projectDetail.ProjectID
projectPositionService.Insert(projectPosition)
For
Each
pph
In
projectPosition.ProjectPositionHours
Dim
pphs
As
New
ProjectPositionHoursService(Master.clsCU.UserId)
pph.ProjectPositionID = positionId
If
pph.ProjectPositionHoursID > 3000
Then
pphs.Insert(pph)
End
If
Next
End
If
Next
'This used to update the project positions, but nhibernate should be doing that for us!
'projectDetail.Update()
bSavedSuccessfully =
True
Catch
ex
As
Exception
ScriptManager.RegisterStartupScript(
Me
,
Me
.
GetType
(),
"ReShowEditModal"
,
"ReshowModal('#editProjectPositionsModal');"
,
True
)
Support.LogError(ex, Master.clsCU.ID,
True
,
Me
)
Finally
If
bSavedSuccessfully =
True
Then
divEditProjectPosition.Visible =
False
LoadDetail(
CLng
(lvResults.SelectedDataKey(0)))
ScriptManager.RegisterStartupScript(
Me
,
Me
.
GetType
(),
"HideEditModal"
,
"HideModal('#editProjectPositionsModal');"
,
True
)
Else
ScriptManager.RegisterStartupScript(
Me
,
Me
.
GetType
(),
"HideEditModal"
,
"HideModal('#editProjectPositionsModal');"
,
True
)
ScriptManager.RegisterStartupScript(
Me
,
Me
.
GetType
(),
"ShowEditModal"
,
"ShowModal('#editProjectPositionsModal');"
,
True
)
End
If
End
Try
End
Sub
New values for "StaffMemberID" is always "" but should be the selected value of the RadDropDownList, oldvalues does not even contain this item.