Hello there. I recently tried using the demo code for the inline grid editing feature hosted on Telerik's website. However, I keep getting the error: Must declare scalar variable '@username'. Any thoughts?
<%@ Page Title="" Language="C#" MasterPageFile="~/Index.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="Custom" TagName="Block" Src="~/Block.ascx" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
<!--
var hasChanges, inputs, dropdowns, editedRow;
function RowClick(sender, eventArgs) {
if (editedRow && hasChanges) {
hasChanges = false;
if (confirm("Update changes?")) {
$find("<%= RadGrid1.MasterTableView.ClientID %>").updateItem(editedRow);
}
}
}
function RowDblClick(sender, eventArgs) {
editedRow = eventArgs.get_itemIndexHierarchical();
$find("<%= RadGrid1.MasterTableView.ClientID %>").editItem(editedRow);
}
function GridCommand(sender, args) {
if (args.get_commandName() != "Edit") {
editedRow = null;
}
}
function GridCreated(sender, eventArgs) {
var gridElement = sender.get_element();
var elementsToUse = [];
inputs = gridElement.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
var lowerType = inputs[i].type.toLowerCase();
if (lowerType == "hidden" || lowerType == "button") {
continue;
}
Array.add(elementsToUse, inputs[i]);
inputs[i].onchange = TrackChanges;
}
dropdowns = gridElement.getElementsByTagName("select");
for (var i = 0; i < dropdowns.length; i++) {
dropdowns[i].onchange = TrackChanges;
}
setTimeout(function() { if (elementsToUse[0]) elementsToUse[0].focus(); }, 100);
}
function TrackChanges(e) {
hasChanges = true;
}
-->
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
<telerik:AjaxUpdatedControl ControlID="Label1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<br />
<telerik:RadGrid ID="RadGrid1" DataSourceID="SessionDataSource1" Width="97%" ShowStatusBar="True"
AllowSorting="True" PageSize="7" GridLines="None" AllowPaging="True" runat="server"
AllowAutomaticUpdates="True" OnItemUpdated="RadGrid1_ItemUpdated" AutoGenerateColumns="False"
OnDataBound="RadGrid1_DataBound" Skin="WebBlue">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</HeaderContextMenu>
<MasterTableView TableLayout="Fixed" DataKeyNames="username" EditMode="PopUp">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn UniqueName="username" DataField="username" HeaderText="username"
ReadOnly="True" HeaderStyle-Width="10%" SortExpression="username">
<HeaderStyle Width="10%"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn ReadOnly="true" UniqueName="password" DataField="password" HeaderText="password"
HeaderStyle-Width="25%" SortExpression="password">
<HeaderStyle Width="25%"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="isAdmin" DataField="isAdmin" HeaderText="isAdmin"
HeaderStyle-Width="20%" SortExpression="isAdmin">
<HeaderStyle Width="20%"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="First_name" HeaderText="First_name" SortExpression="First_name"
UniqueName="First_name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Last_name" HeaderText="Last_name" SortExpression="Last_name"
UniqueName="Last_name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Effective_date" DataType="System.DateTime" HeaderText="Effective_date"
SortExpression="Effective_date" UniqueName="Effective_date">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RAC" HeaderText="RAC" SortExpression="RAC" UniqueName="RAC">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowClick="RowClick" OnRowDblClick="RowDblClick" OnGridCreated="GridCreated"
OnCommand="GridCommand" />
</ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
</telerik:RadGrid>
<telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="180px" />
<telerik:GridDropDownListColumnEditor ID="GridDropDownListColumnEditor1" runat="server"
DropDownStyle-Width="70px" />
<telerik:GridCheckBoxColumnEditor ID="GridCheckBoxColumnEditor1" runat="server" CheckBoxStyle-BorderWidth="2" />
<telerik:GridNumericColumnEditor ID="GridNumericColumnEditor1" runat="server" NumericTextBox-Width="50px" />
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="false" />
<br />
<asp:SqlDataSource ID="SessionDataSource1" ConnectionString="<%$ ConnectionStrings:RVCConnectionString %>"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [users]"
runat="server" ConflictDetection="CompareAllValues" UpdateCommand="UPDATE [users] SET [password] = @password,[isAdmin] = @isAdmin,[First_name] = @First_name,[Last_name] = @Last_name,[Effective_date] = @Effective_date,[RAC] = @RAC WHERE [username] = @username">
<UpdateParameters>
<asp:Parameter Name="username" Type="String" />
<asp:Parameter Name="password" Type="String" />
<asp:Parameter Name="isAdmin" Type="String" />
<asp:Parameter Name="firstName" Type="String" />
<asp:Parameter Name="lastName" Type="String" />
<asp:Parameter Name="Effective_date" Type="DateTime" />
<asp:Parameter Name="RAC" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>
<%@ Page Title="" Language="C#" MasterPageFile="~/Index.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="Custom" TagName="Block" Src="~/Block.ascx" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
<!--
var hasChanges, inputs, dropdowns, editedRow;
function RowClick(sender, eventArgs) {
if (editedRow && hasChanges) {
hasChanges = false;
if (confirm("Update changes?")) {
$find("<%= RadGrid1.MasterTableView.ClientID %>").updateItem(editedRow);
}
}
}
function RowDblClick(sender, eventArgs) {
editedRow = eventArgs.get_itemIndexHierarchical();
$find("<%= RadGrid1.MasterTableView.ClientID %>").editItem(editedRow);
}
function GridCommand(sender, args) {
if (args.get_commandName() != "Edit") {
editedRow = null;
}
}
function GridCreated(sender, eventArgs) {
var gridElement = sender.get_element();
var elementsToUse = [];
inputs = gridElement.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
var lowerType = inputs[i].type.toLowerCase();
if (lowerType == "hidden" || lowerType == "button") {
continue;
}
Array.add(elementsToUse, inputs[i]);
inputs[i].onchange = TrackChanges;
}
dropdowns = gridElement.getElementsByTagName("select");
for (var i = 0; i < dropdowns.length; i++) {
dropdowns[i].onchange = TrackChanges;
}
setTimeout(function() { if (elementsToUse[0]) elementsToUse[0].focus(); }, 100);
}
function TrackChanges(e) {
hasChanges = true;
}
-->
</script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
<telerik:AjaxUpdatedControl ControlID="Label1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<br />
<telerik:RadGrid ID="RadGrid1" DataSourceID="SessionDataSource1" Width="97%" ShowStatusBar="True"
AllowSorting="True" PageSize="7" GridLines="None" AllowPaging="True" runat="server"
AllowAutomaticUpdates="True" OnItemUpdated="RadGrid1_ItemUpdated" AutoGenerateColumns="False"
OnDataBound="RadGrid1_DataBound" Skin="WebBlue">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</HeaderContextMenu>
<MasterTableView TableLayout="Fixed" DataKeyNames="username" EditMode="PopUp">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn UniqueName="username" DataField="username" HeaderText="username"
ReadOnly="True" HeaderStyle-Width="10%" SortExpression="username">
<HeaderStyle Width="10%"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn ReadOnly="true" UniqueName="password" DataField="password" HeaderText="password"
HeaderStyle-Width="25%" SortExpression="password">
<HeaderStyle Width="25%"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="isAdmin" DataField="isAdmin" HeaderText="isAdmin"
HeaderStyle-Width="20%" SortExpression="isAdmin">
<HeaderStyle Width="20%"></HeaderStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="First_name" HeaderText="First_name" SortExpression="First_name"
UniqueName="First_name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Last_name" HeaderText="Last_name" SortExpression="Last_name"
UniqueName="Last_name">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Effective_date" DataType="System.DateTime" HeaderText="Effective_date"
SortExpression="Effective_date" UniqueName="Effective_date">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RAC" HeaderText="RAC" SortExpression="RAC" UniqueName="RAC">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowClick="RowClick" OnRowDblClick="RowDblClick" OnGridCreated="GridCreated"
OnCommand="GridCommand" />
</ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
</telerik:RadGrid>
<telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="180px" />
<telerik:GridDropDownListColumnEditor ID="GridDropDownListColumnEditor1" runat="server"
DropDownStyle-Width="70px" />
<telerik:GridCheckBoxColumnEditor ID="GridCheckBoxColumnEditor1" runat="server" CheckBoxStyle-BorderWidth="2" />
<telerik:GridNumericColumnEditor ID="GridNumericColumnEditor1" runat="server" NumericTextBox-Width="50px" />
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="false" />
<br />
<asp:SqlDataSource ID="SessionDataSource1" ConnectionString="<%$ ConnectionStrings:RVCConnectionString %>"
OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [users]"
runat="server" ConflictDetection="CompareAllValues" UpdateCommand="UPDATE [users] SET [password] = @password,[isAdmin] = @isAdmin,[First_name] = @First_name,[Last_name] = @Last_name,[Effective_date] = @Effective_date,[RAC] = @RAC WHERE [username] = @username">
<UpdateParameters>
<asp:Parameter Name="username" Type="String" />
<asp:Parameter Name="password" Type="String" />
<asp:Parameter Name="isAdmin" Type="String" />
<asp:Parameter Name="firstName" Type="String" />
<asp:Parameter Name="lastName" Type="String" />
<asp:Parameter Name="Effective_date" Type="DateTime" />
<asp:Parameter Name="RAC" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>