Hello!
I'd like some help on two issues that I'm running into while using "EditMode=Batch" on a RadGrid that's bound to an object data source. The Grid is simple with just 3 columns and 4 hidden columns. In those 3 visible columns, only the 3rd column is the editable column. The first two columns are last_update (date) and who (updated).
For inserts, I'd like that to be a static label values with last_update = today's date and who will be the currently logged in use who is in a Session Variable.
For updates, I was trying to display those two labels with whatever the values that were retrieved and while while inserting the actual values, I wanted to override the values of last_update with the recent date/time and whoever the new user that's editing the record for "who" column.
This simple task of displaying this using <ClientEvents OnBatchEditOpening="SetLabels" /> javascript was absolutely tedious task and I am not sure whether these two columns can be a Bound Column or does it have to be a template column with Label controls inside for both edit and insert?
I've provided some code snippets here.
NOTE: This page is called inside a RadTab strip control which is part of another page with Master Page that has the radscript manager and window manager etc as well. I'm not sure whether for this reason, we encounter another issue with enabling the first three lines of javascript below. Because whenever those lines are uncommented, the "Batch Edit" mode automatically becomes "Form Edit" mode and the javascript doesn't fire.
Any help is appreciated.
Thank you!
I'd like some help on two issues that I'm running into while using "EditMode=Batch" on a RadGrid that's bound to an object data source. The Grid is simple with just 3 columns and 4 hidden columns. In those 3 visible columns, only the 3rd column is the editable column. The first two columns are last_update (date) and who (updated).
For inserts, I'd like that to be a static label values with last_update = today's date and who will be the currently logged in use who is in a Session Variable.
For updates, I was trying to display those two labels with whatever the values that were retrieved and while while inserting the actual values, I wanted to override the values of last_update with the recent date/time and whoever the new user that's editing the record for "who" column.
This simple task of displaying this using <ClientEvents OnBatchEditOpening="SetLabels" /> javascript was absolutely tedious task and I am not sure whether these two columns can be a Bound Column or does it have to be a template column with Label controls inside for both edit and insert?
I've provided some code snippets here.
NOTE: This page is called inside a RadTab strip control which is part of another page with Master Page that has the radscript manager and window manager etc as well. I'm not sure whether for this reason, we encounter another issue with enabling the first three lines of javascript below. Because whenever those lines are uncommented, the "Batch Edit" mode automatically becomes "Form Edit" mode and the javascript doesn't fire.
Any help is appreciated.
Thank you!
<!DOCTYPE html>
<
html
>
<
head
id
=
"Head1"
runat
=
"server"
>
<
title
>GDBID - Invoice Notes</
title
>
<
script
type
=
"text/javascript"
>
function SetLabels(sender, args) {
//var RowID = args.get_id(); //get Row
//var masterTable = document.getElementById("RadGrid1").get_masterTableView(); //get Grid
//var ControlX = masterTable.get_dataItems()[RowID].findElement('lblLastUpdateInsert').id; //get Control ID
if (args.get_columnUniqueName() == "last_update") {
var cardStatusCell = sender.get_masterTableView()._getCellByColumnUniqueNameFromTableRowElement(args.get_row(), "last_update");
//alert(sender.get_batchEditingManager().getCellValue(cardStatusCell));
//sender.get_batchEditingManager().changeCellValue(cardStatusCell, "10/28/2014");
var txtBox = document.getElementById("RadGrid1_RadGrid1_ctl00_last_update_TB_last_update");
if (txtBox != null) { txtBox.value = "Hello World"; txtBox.disabled = true; }
}
</
script
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
runat
=
"server"
ID
=
"RadScriptManager1"
EnablePartialRendering
=
"true"
EnablePageMethods
=
"true"
LoadScriptsBeforeUI
=
"true"
AsyncPostBackTimeout
=
"600"
EnableScriptCombine
=
"false"
ScriptMode
=
"Release"
>
<
Groups
>
<
telerik:ScriptReferenceGroup
>
<
Scripts
>
<
asp:ScriptReference
Path
=
"~/Scripts/jquery-1.4.1.js"
/>
<
asp:ScriptReference
Path
=
"~/Scripts/json2.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.Core.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQuery.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQueryInclude.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQueryPlugins.js"
/>
</
Scripts
>
</
telerik:ScriptReferenceGroup
>
</
Groups
>
</
telerik:RadScriptManager
>
<
telerik:RadAjaxPanel
runat
=
"server"
ID
=
"RadAjaxPanel1"
>
<
asp:Table
ID
=
"tblInvoiceNotes"
runat
=
"server"
CssClass
=
""
>
<
asp:TableRow
>
<
asp:TableCell
>
<
telerik:RadGrid
ID
=
"RadGrid1"
GridLines
=
"None"
runat
=
"server"
PageSize
=
"10"
Skin
=
"Telerik"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
AllowPaging
=
"True"
AutoGenerateColumns
=
"False"
Width
=
"750px"
DataSourceID
=
"objDataSourceIN"
OnBatchEditCommand
=
"RadGrid1_BatchEditCommand"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
OnInsertCommand
=
"RadGrid1_InsertCommand"
OnDeleteCommand
=
"RadGrid1_DeleteCommand"
>
<
ValidationSettings
EnableModelValidation
=
"true"
EnableValidation
=
"true"
CommandsToValidate
=
"Update,InitInsert,Insert"
/>
<
MasterTableView
CommandItemDisplay
=
"Top"
DataKeyNames
=
"InvNum,InvDbId,InvNotesNum"
AutoGenerateColumns
=
"False"
DataSourceID
=
"objDataSourceIN"
HorizontalAlign
=
"NotSet"
EditMode
=
"Batch"
>
<
BatchEditingSettings
EditType
=
"Cell"
OpenEditingEvent
=
"Click"
/>
<%-- <
SortExpressions
><
telerik:GridSortExpression
FieldName
=
"last_update"
SortOrder
=
"Descending"
/></
SortExpressions
>--%>
<
Columns
>
<%--<
telerik:GridTemplateColumn
HeaderText
=
"Date"
UniqueName
=
"last_update"
HeaderStyle-Width
=
"150px"
DataField
=
"last_update"
>
<
ItemTemplate
><%# Eval("last_update") %></
ItemTemplate
>
<
EditItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblLastUpdateEdit"
Text='<%#Eval("last_update")%>' Visible="true"></
asp:Label
>
</
EditItemTemplate
>
<
InsertItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblLastUpdateInsert"
Text="<%= DateTime.Now.ToShortDateString() %>" Visible="true"></
asp:Label
>
</
InsertItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Who"
UniqueName
=
"who"
HeaderStyle-Width
=
"200px"
DataField
=
"who"
>
<
ItemTemplate
><%# Eval("who") %></
ItemTemplate
>
<
EditItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblWhoEdit"
Text='<%#Eval("who")%>'></
asp:Label
>
</
EditItemTemplate
>
<
InsertItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblWhoInsert"
Text
=
""
Visible
=
"true"
></
asp:Label
>
</
InsertItemTemplate
>
</
telerik:GridTemplateColumn
>--%>
<
telerik:GridBoundColumn
DataField
=
"last_update"
HeaderStyle-Width
=
"150px"
HeaderText
=
"Date"
SortExpression
=
"last_update"
UniqueName
=
"last_update"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"who"
HeaderStyle-Width
=
"200px"
HeaderText
=
"Who"
SortExpression
=
"who"
UniqueName
=
"who"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Notes"
HeaderStyle-Width
=
"410px"
HeaderText
=
"Notes"
SortExpression
=
"Notes"
UniqueName
=
"Notes"
>
<
ColumnValidationSettings
EnableRequiredFieldValidation
=
"true"
>
<
RequiredFieldValidator
ForeColor
=
"Red"
Text
=
"*This field is required"
Display
=
"Dynamic"
>
</
RequiredFieldValidator
>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"InvNum"
DataType
=
"System.Int32"
HeaderText
=
"InvNum"
UniqueName
=
"InvNum"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"InvDbId"
DataType
=
"System.Int32"
HeaderText
=
"InvDbId"
UniqueName
=
"InvDbId"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"InvNotesNum"
DataType
=
"System.Int32"
HeaderText
=
"InvNotesNum"
UniqueName
=
"InvNotesNum"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"AllowEdit"
DataType
=
"System.String"
HeaderText
=
"AllowEdit"
UniqueName
=
"AllowEdit"
Display
=
"false"
>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Delete this Note?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
HeaderText
=
"Delete"
HeaderStyle-Width
=
"50px"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
ImageUrl
=
"Images\GridRowDelete.gif"
>
</
telerik:GridButtonColumn
>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
AllowKeyboardNavigation
=
"true"
>
<
ClientEvents
OnBatchEditOpening
=
"SetLabels"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
<
asp:Label
ID
=
"SavedChangesList"
runat
=
"server"
Text
=
""
ForeColor
=
"Red"
Font-Names
=
"Calibri"
></
asp:Label
>
</
asp:TableCell
>
</
asp:TableRow
>
</
asp:Table
>
</
telerik:RadAjaxPanel
>
<
asp:ObjectDataSource
ID
=
"objDataSourceIN"
runat
=
"server"
TypeName
=
"Notes"
SelectMethod
=
"GetData"
InsertMethod
=
"Insert"
UpdateMethod
=
"Update"
DeleteMethod
=
"Delete"
EnablePaging
=
"false"
EnableCaching
=
"true"
>
<
SelectParameters
>
<
asp:SessionParameter
Name
=
"user"
SessionField
=
"UserName"
Type
=
"String"
/>
<
asp:SessionParameter
Name
=
"location"
SessionField
=
"Location"
Type
=
"String"
/>
<
asp:QueryStringParameter
Name
=
"searchinvnuminvdbid"
QueryStringField
=
"InvNumInvDbId"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"searchdetailnum"
Type
=
"String"
DefaultValue
=
""
/>
</
SelectParameters
>
<
InsertParameters
>
<
asp:SessionParameter
Name
=
"user"
SessionField
=
"UserName"
Type
=
"String"
/>
<
asp:SessionParameter
Name
=
"location"
SessionField
=
"Location"
Type
=
"String"
/>
<
asp:QueryStringParameter
Name
=
"searchinvnuminvdbid"
QueryStringField
=
"InvNumInvDbId"
Type
=
"String"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:SessionParameter
Name
=
"user"
SessionField
=
"UserName"
Type
=
"String"
/>
<
asp:SessionParameter
Name
=
"location"
SessionField
=
"Location"
Type
=
"String"
/>
</
UpdateParameters
>
<
DeleteParameters
>
<
asp:SessionParameter
Name
=
"user"
SessionField
=
"UserName"
Type
=
"String"
/>
<
asp:SessionParameter
Name
=
"location"
SessionField
=
"Location"
Type
=
"String"
/>
</
DeleteParameters
>
</
asp:ObjectDataSource
>
</
form
>
</
body
>
</
html
>