or
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
></
telerik:RadScriptManager
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
></
telerik:RadAjaxManager
>
<
div
>
<
asp:PlaceHolder
ID
=
"PlaceHolder1"
runat
=
"server"
></
asp:PlaceHolder
>
</
div
>
</
form
>
</
body
>
</
html
>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
Telerik.Web.UI;
public
partial
class
Default3 : System.Web.UI.Page
{
protected
RadGrid RadGridNote =
null
;
private
int
NoteId
{
get
{
if
(ViewState[
"Id"
] ==
null
)
{
ViewState[
"Id"
] = 0;
}
ViewState[
"Id"
] = (
int
)ViewState[
"Id"
] + 1;
return
(
int
)ViewState[
"Id"
];
}
}
private
List<Note> NotesList
{
get
{
if
(ViewState[
"NotesList"
] ==
null
)
{
// Initialize list.
List<Note> list =
new
List<Note>();
Note note;
note =
new
Note();
note.NoteId = NoteId;
note.NoteText =
"This is the first note."
;
list.Add(note);
note =
new
Note();
note.NoteId = NoteId;
note.NoteText =
"This is the seconds note."
;
list.Add(note);
ViewState[
"NotesList"
] = list;
}
return
(List<Note>)ViewState[
"NotesList"
];
}
set
{ ViewState[
"NotesList"
] = value; }
}
override
protected
void
OnInit(EventArgs e)
{
base
.OnInit(e);
InitializeGridNote();
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGridNote, RadGridNote);
}
private
void
InitializeGridNote()
{
GridBoundColumn boundColumn;
GridButtonColumn buttonColumn;
GridEditCommandColumn editCommandColumn;
GridHTMLEditorColumn htmlEditorColumn;
this
.RadGridNote =
new
RadGrid();
// Set required event handlers.
RadGridNote.NeedDataSource +=
new
GridNeedDataSourceEventHandler(RadGridNote_NeedDataSource);
RadGridNote.InsertCommand +=
new
GridCommandEventHandler(RadGridNote_InsertCommand);
RadGridNote.UpdateCommand +=
new
GridCommandEventHandler(RadGridNote_UpdateCommand);
RadGridNote.DeleteCommand +=
new
GridCommandEventHandler(RadGridNote_DeleteCommand);
RadGridNote.ID =
"RadGridNote"
;
RadGridNote.AutoGenerateColumns =
false
;
RadGridNote.AllowMultiRowEdit =
false
;
RadGridNote.AllowSorting =
true
;
RadGridNote.Width = Unit.Percentage(100);
RadGridNote.ClientSettings.Selecting.AllowRowSelect =
true
;
RadGridNote.MasterTableView.DataKeyNames =
new
string
[] {
"NoteId"
};
RadGridNote.MasterTableView.DataMember =
"Note"
;
RadGridNote.MasterTableView.EditMode = GridEditMode.InPlace;
RadGridNote.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
RadGridNote.MasterTableView.CommandItemSettings.AddNewRecordText =
"Add New Note"
;
// Edit button.
editCommandColumn =
new
GridEditCommandColumn();
RadGridNote.MasterTableView.Columns.Add(editCommandColumn);
editCommandColumn.ButtonType = GridButtonColumnType.ImageButton;
editCommandColumn.UniqueName =
"EditCommandColumn"
;
editCommandColumn.ItemStyle.Width = Unit.Percentage(10);
// Delete button.
buttonColumn =
new
GridButtonColumn();
RadGridNote.MasterTableView.Columns.Add(buttonColumn);
buttonColumn.ButtonType = GridButtonColumnType.ImageButton;
buttonColumn.UniqueName =
"DeleteCommandColumn"
;
buttonColumn.CommandName =
"Delete"
;
buttonColumn.ItemStyle.Width = Unit.Percentage(5);
boundColumn =
new
GridBoundColumn();
RadGridNote.MasterTableView.Columns.Add(boundColumn);
boundColumn.ReadOnly =
true
;
boundColumn.UniqueName =
"NoteId"
;
boundColumn.DataField =
"NoteId"
;
boundColumn.HeaderText =
"Id"
;
boundColumn.ItemStyle.Width = Unit.Percentage(10);
htmlEditorColumn =
new
GridHTMLEditorColumn();
RadGridNote.MasterTableView.Columns.Add(htmlEditorColumn);
htmlEditorColumn.UniqueName =
"NoteText"
;
htmlEditorColumn.DataField =
"NoteText"
;
htmlEditorColumn.HeaderText =
"Note"
;
htmlEditorColumn.ItemStyle.Width = Unit.Percentage(75);
PlaceHolder1.Controls.Add(RadGridNote);
}
void
RadGridNote_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
RadGridNote.MasterTableView.DataSource = NotesList;
}
void
RadGridNote_InsertCommand(
object
sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item
as
GridEditableItem;
GridEditManager editManager = editedItem.EditManager;
Note note =
new
Note();
note.NoteId = NoteId;
note.NoteText = (editManager.GetColumnEditor(
"NoteText"
)
as
GridHTMLEditorColumnEditor).Editor.Content;
NotesList.Add(note);
}
void
RadGridNote_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item
as
GridEditableItem;
GridEditManager editManager = editedItem.EditManager;
// Obtain the ID for the contract step.
int
noteId =
int
.Parse(editedItem.GetDataKeyValue(
"NoteId"
).ToString());
Note foundNote = NotesList.Find(
delegate
(Note note) {
return
(note.NoteId == noteId); });
if
(foundNote !=
null
)
{
foundNote.NoteText = (editManager.GetColumnEditor(
"NoteText"
)
as
GridHTMLEditorColumnEditor).Editor.Content;
}
}
void
RadGridNote_DeleteCommand(
object
sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item
as
GridEditableItem;
GridEditManager editManager = editedItem.EditManager;
// Obtain the ID for the contract step.
int
noteId =
int
.Parse(editedItem.GetDataKeyValue(
"NoteId"
).ToString());
Note foundNote = NotesList.Find(
delegate
(Note note) {
return
(note.NoteId == noteId); });
if
(foundNote !=
null
)
{
NotesList.Remove(foundNote);
}
}
[Serializable]
private
class
Note
{
public
int
NoteId
{
get
;
set
;
}
public
string
NoteText
{
get
;
set
;
}
}
}
EnableEmbeddedBaseStylesheet =
false
;
EnableEmbeddedScripts =
false
;
EnableEmbeddedSkins =
false
;
RegisterWithScriptManager =
false
;
var scripts =
new
List<ScriptReference>();
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadGrid)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadTabStrip)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadMultiPage)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadComboBox)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadInputManager)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadFilter)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadMenu)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadContextMenu)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadInputControl)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadMaskedTextBox)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadToolTip)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadToolTipManager)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadNumericTextBox)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadUpload)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadAsyncUpload)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadTreeView)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadTextBox)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadCalendar)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadDatePicker)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadDateTimePicker)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadMonthYearPicker)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadTimeView)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadTimePicker)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadDateInput)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadScriptManager)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadAjaxManager)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadToolBar)));
scripts.AddRange(ScriptObjectBuilder.GetScriptReferences(
typeof
(RadDate)));
foreach
(var script
in
scripts)
RadScriptManager1.Scripts.Add(script);
var ctl =
new
RadNumericTextBox();
ctl.ID =
"RandomId"
;
ctl.NumberFormat.AllowRounding =
false
;
ctl.NumberFormat.DecimalDigits = 0;
ctl.NumberFormat.GroupSeparator =
""
;
ctl.MinValue = 1;
ctl.MaxValue =
int
.MaxValue;
ctl.ClientEvents.OnKeyPress =
"onKeyPress"
;
ctl.ClientEvents.OnBlur =
"onBlur"
;
ctl.Value = 1;
ctl.EnableEmbeddedBaseStylesheet =
false
;
ctl.EnableEmbeddedScripts =
false
;
ctl.EnableEmbeddedSkins =
false
;
ctl.RegisterWithScriptManager =
false
;
protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridGroupHeaderItem)
{
createbutton((GridGroupHeaderItem)e.Item);
}
}
protected void createbutton(GridGroupHeaderItem header)
{
if (header.DataCell.FindControl("thisGroup") == null)
{
Label mylab = new Label();
mylab.ID = "thisNumber";
DataRowView drv = header.DataItem as DataRowView;
mylab.Text = drv["Location"].ToString();
Label mylabno = new Label();
mylab.ID = "thisGroup";
mylabno.Text = drv["GroupOrder"].ToString();
mylabno.Visible = false;
GridGroupHeaderItem item = header as GridGroupHeaderItem;
LinkButton lnk = new LinkButton();
lnk.Text = "Move up ";
lnk.Style.Add("margin", "3px");
LinkButton xnk = new LinkButton();
xnk.Text = "Move down";
xnk.Style.Add("margin", "2px");
xnk.Style.Add("padding", "2px");
item.DataCell.Controls.Add(mylab);
item.DataCell.Controls.Add(mylabno);
lnk.CommandName = "Up";
item.DataCell.Controls.Add(lnk);
xnk.CommandName = "Down";
item.DataCell.Controls.Add(xnk);
}
}
I'm guessing its related to the fact this radgrid is ajaxified, but not entirely sure. any ideas??