http://www.telerik.com/help/aspnet-ajax/grid-performing-batch-updates.html
I'm trying to use the example in that demo to allow someone to edit multiples rows in a grid and then submit the changes all at once. However, I keep getting the following error:
I'm not sure what's wrong here. In my Radgrid1_ItemCommand function I've left out ALL of the code - it's just an empty function that does nothing. and i still get the above error. Any suggestions?
ASPX
CS
I'm trying to use the example in that demo to allow someone to edit multiples rows in a grid and then submit the changes all at once. However, I keep getting the following error:
Unable to cast object of type 'Telerik.Web.UI.GridCommandItem' to type 'Telerik.Web.UI.GridEditableItem'
I'm not sure what's wrong here. In my Radgrid1_ItemCommand function I've left out ALL of the code - it's just an empty function that does nothing. and i still get the above error. Any suggestions?
ASPX
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
></
telerik:RadScriptManager
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
CellSpacing
=
"0"
DataSourceID
=
"SqlDataSource1"
GridLines
=
"None"
AutoGenerateEditColumn
=
"True"
AllowMultiRowEdit
=
"True"
Width
=
"40%"
OnPreRender
=
"RadGrid1_PreRender"
AllowAutomaticUpdates
=
"True"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"ID"
DataSourceID
=
"SqlDataSource1"
EditMode
=
"InPlace"
CommandItemDisplay
=
"Top"
>
<
CommandItemTemplate
>
<
asp:LinkButton
ID
=
"btnUpdate"
runat
=
"server"
CommandName
=
"Update"
Visible
=
'true'
Text
=
"Update"
Font-Bold
=
"True"
Font-Size
=
"Larger"
/>
</
CommandItemTemplate
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
Visible
=
"True"
FilterControlAltText
=
"Filter ExpandColumn column"
Created
=
"True"
>
<
HeaderStyle
Width
=
"20px"
></
HeaderStyle
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ID"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter ID column"
HeaderText
=
"ID"
ReadOnly
=
"True"
SortExpression
=
"ID"
UniqueName
=
"ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Name"
FilterControlAltText
=
"Filter Name column"
HeaderText
=
"Name"
SortExpression
=
"Name"
UniqueName
=
"Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridCheckBoxColumn
DataField
=
"IsParent"
DataType
=
"System.Boolean"
FilterControlAltText
=
"Filter IsParent column"
HeaderText
=
"IsParent"
SortExpression
=
"IsParent"
UniqueName
=
"IsParent"
>
</
telerik:GridCheckBoxColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
></
EditColumn
>
</
EditFormSettings
>
<
PagerStyle
PageSizeControlType
=
"RadComboBox"
></
PagerStyle
>
</
MasterTableView
>
<
PagerStyle
PageSizeControlType
=
"RadComboBox"
></
PagerStyle
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
</
telerik:RadGrid
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:MachineSalesConnectionString1 %>" SelectCommand="SELECT [ID], [Name], [IsParent] FROM [Manufacturer]" UpdateCommand="UPDATE [Manufacturer] SET [Name] = @Name, [IsParent] = @IsParent WHERE [ID] = @ID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"ID"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"Name"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"IsParent"
Type
=
"Boolean"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"Name"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"IsParent"
Type
=
"Boolean"
/>
<
asp:Parameter
Name
=
"ID"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
CS
using
System;
using
Telerik.Web.UI;
public
partial
class
Default2 : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
RadGrid1_PreRender(
object
sender, System.EventArgs e)
{
if
(!IsPostBack)
{
foreach
(GridItem item
in
RadGrid1.MasterTableView.Items)
{
if
(item
is
GridEditableItem)
{
GridEditableItem editableItem = item
as
GridDataItem;
editableItem.Edit =
true
;
}
}
RadGrid1.Rebind();
}
}
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
// if (e.CommandName == "UpdateAll")
// {
// foreach (GridEditableItem editedItem in RadGrid1.EditItems)
// {
// Hashtable newnewValues = new Hashtable();
// //The GridTableView will fill the values from all editable columns in the hash
// e.Item.OwnerTableView.ExtractValuesFromItem(newnewValues, editedItem);
// SqlDataSource1.UpdateCommand = String.Format("Update Manufacturers SET IsParent={0} WHERE ID={1}", newnewValues["IsParent"], editedItem["ID"].Text);
// SqlDataSource1.Update();
// editedItem.Edit = false;
// }
// }
// RadGrid1.Rebind();
}
}