I would like to click on my grid client select column, hit the edit button, and retain the checked/selected state of the item after postback, but for some reason the SelectItems count of the grid is 0 after databinding.
<
Rad:RadGrid
ID
=
"testgrid"
OnNeedDataSource
=
"testgrid_NeedDataSource"
ClientSettings-Selecting-AllowRowSelect
=
"true"
runat
=
"server"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
EditMode
=
"InPlace"
>
<
CommandItemTemplate
>
<
Asp:LinkButton
ID
=
"btnEditSelected"
runat
=
"server"
CommandName
=
"EditSelected"
EnableViewState
=
"true"
CausesValidation
=
"false"
Visible
=
"true"
Text
=
"Edit"
/>
</
CommandItemTemplate
>
<
Columns
>
<
Rad:GridClientSelectColumn
UniqueName
=
"testselect"
>
</
Rad:GridClientSelectColumn
>
</
Columns
>
</
MasterTableView
>
</
Rad:RadGrid
>
protected void testgrid_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
IList<
string
> items = new List<
string
>();
items.Add("test");
testgrid.DataSource = items;
}
Hello,
I have a 'record update' feature enabled grid (2012 Q1).
I am using <FormTemplate> for editing/updating the data on the grid.
In the FormTemplate, I have a RadioButtonList named 'rdGrade' which is bound to the 'SchoolGrade' field in my database. The code for this RadioButtonList is as shown below.
<
asp:RadioButtonList
ID
=
"rdGrade"
runat
=
"server"
SelectedValue='<%# Bind("SchoolGrade") %>'
DataSource='<%# (new string[] { "4", "5", "6" }) %>'
AppendDataBoundItems="True"
RepeatDirection="Horizontal">
</
asp:RadioButtonList
>
Editing the SchoolGrade field with this RadioButtonList was fine. No errors.
But when I try to Add a new record by clicking the "+ Add new record" button, I get an error. So I had to add some extra code to the code behind page to set the default selected value of this RadioButtonList and the code I added was:
protected
void
RadGrid1_ItemCommand(
object
source, Telerik.Web.UI.GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.InitInsertCommandName)
{
//Add new" button clicked
e.Canceled =
true
;
//Prepare an IDictionary with the predefined values
System.Collections.Specialized.ListDictionary newValues =
new
System.Collections.Specialized.ListDictionary();
newValues[
"SchoolGrade"
] = 5;
//Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues);
}
}
The code above sets the default selected value of the radio button list as 5.
My question is how do I change the code line
newValues[
"SchoolGrade"
] = 5;
in order to initially UNCHECK the RadioButtonList rdGrade when a user clicks the 'Add new record' button on the grid?
Thank you.
<
script
type
=
"text/javascript"
>
function OnClientUpdated(sender, args) {
var message = "Update (check) was done!";
var newMsgs = sender.get_value();
if (newMsgs != 0) {
sender.show();
message += (newMsgs == 1) ? (" There is 1 new message!") : (" There are " + newMsgs + " new messages!");
}
else {
message += " There are no new messages!";
}
}
</
script
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadScriptBlock
runat
=
"server"
ID
=
"scriptBlock"
>
<
script
type
=
"text/javascript"
>
<!--
function onRowDropping(sender, args) {
if (sender.get_id() == "<%=RadGrid1.ClientID %>") {
var node = args.get_destinationHtmlElement();
if (!isChildOf('<%=RadGrid2.ClientID %>', node) && !isChildOf('<%=RadGrid1.ClientID %>', node)) {
args.set_cancel(true);
}
}
else {
var node = args.get_destinationHtmlElement();
if (!isChildOf('trashCan', node)) {
args.set_cancel(true);
}
else {
if (confirm("Are you sure you want to delete this order?"))
args.set_destinationHtmlElement($get('trashCan'));
else
args.set_cancel(true);
}
}
}
function isChildOf(parentId, element) {
while (element) {
if (element.id && element.id.indexOf(parentId) > -1) {
return true;
}
element = element.parentNode;
}
return false;
}
-->
</
script
>
</
telerik:RadScriptBlock
>
<
telerik:RadAjaxPanel
ID
=
"RadAjaxPanel1"
runat
=
"server"
>
<
telerik:RadSplitter
ID
=
"RadSplitter1"
Width
=
"100%"
runat
=
"server"
>
<
telerik:RadPane
runat
=
"server"
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowFilteringByColumn
=
"true"
onneeddatasource
=
"RadGrid1_NeedDataSource"
onrowdrop
=
"RadGrid1_RowDrop"
>
<
MasterTableView
AllowCustomSorting
=
"true"
AllowPaging
=
"true"
DataKeyNames
=
"ID"
AllowSorting
=
"true"
PageSize
=
"20"
>
</
MasterTableView
>
<
ClientSettings
AllowRowsDragDrop
=
"True"
AllowColumnsReorder
=
"true"
ReorderColumnsOnClient
=
"true"
>
<
Resizing
AllowColumnResize
=
"true"
/>
<
Selecting
AllowRowSelect
=
"True"
EnableDragToSelectRows
=
"false"
/>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
/>
<
ClientEvents
OnRowDropping
=
"onRowDropping"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
</
telerik:RadPane
>
<
telerik:RadSplitBar
runat
=
"server"
></
telerik:RadSplitBar
>
<
telerik:RadPane
runat
=
"server"
>
<
telerik:RadGrid
ID
=
"RadGrid2"
runat
=
"server"
AllowFilteringByColumn
=
"true"
onneeddatasource
=
"RadGrid2_NeedDataSource"
onrowdrop
=
"RadGrid2_RowDrop"
>
<
MasterTableView
AllowCustomSorting
=
"true"
DataKeyNames
=
"ID"
AllowPaging
=
"true"
AllowSorting
=
"true"
PageSize
=
"20"
>
</
MasterTableView
>
<
ClientSettings
AllowRowsDragDrop
=
"True"
AllowColumnsReorder
=
"true"
ReorderColumnsOnClient
=
"true"
>
<
Resizing
AllowColumnResize
=
"true"
/>
<
ClientEvents
OnRowDropping
=
"onRowDropping"
/>
<
Selecting
AllowRowSelect
=
"True"
EnableDragToSelectRows
=
"false"
/>
<
Scrolling
AllowScroll
=
"true"
UseStaticHeaders
=
"true"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
</
telerik:RadPane
>
</
telerik:RadSplitter
>
</
telerik:RadAjaxPanel
>
<
telerik:RadNotification
ID
=
"RadNotification1"
runat
=
"server"
LoadContentOn
=
"TimeInterval"
Width
=
"300"
Animation
=
"Fade"
EnableRoundedCorners
=
"true"
EnableShadow
=
"true"
OnClientUpdated
=
"OnClientUpdated"
Title
=
"Notifications"
OffsetX
=
"-20"
OffsetY
=
"-20"
TitleIcon
=
"none"
UpdateInterval
=
"10000"
AutoCloseDelay
=
"1500"
OnCallbackUpdate
=
"OnCallbackUpdate"
>
<
ContentTemplate
>
<
asp:Literal
ID
=
"lbl"
runat
=
"server"
></
asp:Literal
>
</
ContentTemplate
>
</
telerik:RadNotification
>
public
IList<Delivery> _Deliveries
{
get
{
return
(List<Delivery>)Session[
"Deliveries"
]; }
set
{ Session[
"Deliveries"
] = value; }
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
_Deliveries =
new
List<Delivery>();
_Deliveries.Add(
new
Delivery { ID = 1, Assigned =
false
, Customer =
"Micross"
, TripDate = DateTime.Today });
_Deliveries.Add(
new
Delivery { ID = 2, Assigned =
false
, Customer =
"Test"
, TripDate = DateTime.Today });
_Deliveries.Add(
new
Delivery { ID = 3, Assigned =
false
, Customer =
"Micross3"
, TripDate = DateTime.Today });
_Deliveries.Add(
new
Delivery { ID = 4, Assigned =
false
, Customer =
"Test3"
, TripDate = DateTime.Today });
RadGrid1.DataBind();
}
}
private
void
BindMain()
{
RadGrid1.DataBind();
}
private
void
BindSecond()
{
RadGrid2.DataSource = _Deliveries.Where(a => a.Assigned ==
true
);
RadGrid2.DataBind();
}
protected
void
OnCallbackUpdate(
object
sender, RadNotificationEventArgs e)
{
int
newMsgs = DateTime.Now.Second % 10;
if
(newMsgs == 5 || newMsgs == 7 || newMsgs == 8 || newMsgs == 9) newMsgs = 0;
lbl.Text = String.Concat(
new
object
[] {
"You have "
, newMsgs,
" new invoices to process!"
});
RadNotification1.Value = newMsgs.ToString();
}
protected
void
RadGrid2_RowDrop(
object
sender, GridDragDropEventArgs e)
{
foreach
(GridDataItem draggedItem
in
e.DraggedItems)
{
var tmpOrder = _Deliveries.Where(a => a.ID == (
long
)draggedItem.GetDataKeyValue(
"ID"
)).Single();
tmpOrder.Assigned =
false
;
}
RadGrid1.Rebind();
RadGrid2.Rebind();
}
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
RadGrid1.DataSource = _Deliveries.Where(a => a.Assigned ==
false
);
}
protected
void
RadGrid2_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
RadGrid2.DataSource = _Deliveries.Where(a => a.Assigned ==
true
);
}
protected
void
RadGrid1_RowDrop(
object
sender, GridDragDropEventArgs e)
{
foreach
(GridDataItem draggedItem
in
e.DraggedItems)
{
var tmpOrder = _Deliveries.Where(a => a.ID == (
long
)draggedItem.GetDataKeyValue(
"ID"
)).Single();
tmpOrder.Assigned =
true
;
}
RadGrid1.Rebind();
RadGrid2.Rebind();
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
</
telerik:RadScriptManager
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"_txtBox"
EventName
=
"OnTextChanged"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"_pnlLine"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"_txtDock"
EventName
=
"OnTextChanged"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"_pnlDock"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
div
>
<
asp:Panel
runat
=
"server"
ID
=
"_pnlLine"
>
<
asp:Label
runat
=
"server"
ID
=
"_lblTime"
Text
=
"Time"
></
asp:Label
><
br
/>
<
asp:TextBox
runat
=
"server"
ID
=
"_txtBox"
OnTextChanged
=
"_txtBox_TextChanged"
AutoPostBack
=
"true"
></
asp:TextBox
><
br
/>
<
asp:TextBox
runat
=
"server"
ID
=
"TextBox1"
Text
=
"Nothing"
></
asp:TextBox
>
</
asp:Panel
>
</
div
>
<
div
>
<
telerik:RadDockLayout
ID
=
"rdlayout"
runat
=
"server"
EnableEmbeddedSkins
=
"true"
>
<
telerik:RadDockZone
ID
=
"rdZone"
runat
=
"server"
Orientation
=
"Vertical"
Width
=
"890px"
FitDocks
=
"true"
CssClass
=
"margin-top: 100px"
>
<
telerik:RadDock
ID
=
"AddLine"
runat
=
"server"
DefaultCommands
=
"ExpandCollapse"
DockMode
=
"Docked"
Width
=
"780px"
Title
=
"Testing"
>
<
ContentTemplate
>
<
div
>
<
asp:Panel
runat
=
"server"
ID
=
"_pnlDock"
>
<
asp:Label
runat
=
"server"
ID
=
"_lblDock"
Text
=
"Time"
></
asp:Label
><
br
/>
<
asp:TextBox
runat
=
"server"
ID
=
"_txtDock"
OnTextChanged
=
"_txtDock_TextChanged"
AutoPostBack
=
"true"
></
asp:TextBox
><
br
/>
<
asp:TextBox
runat
=
"server"
ID
=
"TextBox3"
Text
=
"Nothing"
></
asp:TextBox
>
</
asp:Panel
>
</
div
>
</
ContentTemplate
>
</
telerik:RadDock
>
</
telerik:RadDockZone
>
</
telerik:RadDockLayout
>
</
div
>
</
div
>
</
form
>
</
body
>
</
html
>
using
System;
public
partial
class
Default3 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
_txtBox_TextChanged(
object
sender, EventArgs e)
{
_lblTime.Text = System.DateTime.Now.ToString();
}
protected
void
_txtDock_TextChanged(
object
sender, EventArgs e)
{
_lblDock.Text = System.DateTime.Now.ToString();
}
}