I'm using the Batch Editing example as the basis of a page I'm doing.
It's ideal, because the users need to edit multiple rows and click save. The example does that with the Save Changes at the bottom. The down side is that I need to put in business logic on the create, update, and delete. Normally, I can do that, even with a SQLDataSource, using the SQLDataSource events (ex. PropertyHistories_Updating). The problem is that these events are not triggering.
Yes, I know that I could use Advanced Binding, but am unsure how this example would work with it. :)
Any ideas? (see attached)
Thanks,
Jason
Code:
BatchTest.aspx
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" HorizontalAlign="NotSet">
<p>Hotel Name: <telerik:RadComboBox ID="HotelList" Width="500" runat="server" DataSourceID="Hotels" DataTextField="myview"
AllowCustomText="false" Filter="StartsWith" ShowMoreResultsBox="true" DataValueField="Inncode" />
<p>
</p>
<h3>Property History</h3>
<telerik:RadGrid ID="PropertyHistory" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="PropertyHistories" OnBatchEditCommand="PropertyHistory_BatchEditCommand" OnItemDeleted="PersonnelHistory_ItemDeleted" OnItemInserted="PropertyHistory_ItemInserted" OnItemUpdated="PropertyHistory_ItemUpdated" OnPreRender="PropertyHistory_PreRender" Width="750px">
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Bottom" DataKeyNames="RMCCHistoryID" DataSourceID="PropertyHistories" EditMode="Batch">
<BatchEditingSettings EditType="Row" OpenEditingEvent="Click" />
<SortExpressions>
<telerik:GridSortExpression FieldName="RMCCHistoryID" SortOrder="Descending" />
</SortExpressions>
<Columns>
<telerik:GridTemplateColumn DataField="Model" HeaderText="RMCC Support Model" UniqueName="Class">
<ItemTemplate>
<%# Eval("Model") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="RadComboBox1" runat="server" AllowCustomText="false" DataSourceID="Models" DataTextField="Model" EmptyMessage="Search Models" EnableAutomaticLoadOnDemand="true" Filter="StartsWith" Height="200px" ShowMoreResultsBox="true" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Start Date" UniqueName="startdate">
<ItemTemplate>
<asp:Label ID="date" runat="server" Text='<%# Eval("startdate") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="picker1" runat="server" DbSelectedDate='<%# Bind("startdate") %>' MaxDate="12/31/2173" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="End Date" UniqueName="enddate">
<ItemTemplate>
<asp:Label ID="date" runat="server" Text='<%# Eval("enddate") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="picker1" runat="server" DbSelectedDate='<%# Bind("enddate") %>' MaxDate="12/31/2173" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to Delete?" ConfirmTitle="Delete" HeaderStyle-Width="50px" HeaderText="Delete" Text="Delete" UniqueName="DeleteColumn" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
<p> </p>
<telerik:RadListBox ID="SavedChangesList1" runat="server" Height="200px" Visible="false" Width="600px">
</telerik:RadListBox>
<telerik:RadListBox ID="SavedChangesList" runat="server" Height="200px" Visible="false" Width="600px" />
<asp:SqlDataSource ID="PropertyHistories" runat="server" ConnectionString="<%$ ConnectionStrings:Bob %>" SelectCommand="spUAPPropertyHistory" SelectCommandType="StoredProcedure" DeleteCommand="spUAPPropertyHistoryDelete" DeleteCommandType="StoredProcedure" InsertCommand="spUAPPropertyHistoryInsert" InsertCommandType="StoredProcedure" UpdateCommand="spUAPPropertyHistoryUpdate" UpdateCommandType="StoredProcedure" OnDeleting="PropertyHistories_Deleting" OnInserting="PropertyHistories_Inserting" OnUpdating="PropertyHistories_Updating">
<DeleteParameters>
<asp:Parameter Name="RMCCHistoryID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="RMCCModelLvl2ID" Type="Int32" />
<asp:Parameter Name="RATPropID" Type="Int32" />
<asp:Parameter Name="StartDate" Type="String" />
<asp:Parameter Name="EndDate" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="HotelList" DefaultValue="ABC" Name="Inncode" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="RMCCHistoryID" Type="Int32" />
<asp:Parameter Name="RMCCModelLvl2ID" Type="Int32" />
<asp:Parameter Name="StartDate" Type="String" />
<asp:Parameter Name="EndDate" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="Hotels" runat="server" ConnectionString="<%$ ConnectionStrings:Bob %>" SelectCommand="Select Usename + ' - ' + Inncode as myview, Inncode
From x
Order by 1 Asc">
</asp:SqlDataSource>
<asp:SqlDataSource ID="Contacts" runat="server" ConnectionString="<%$ ConnectionStrings:Bob %>" SelectCommand="Select Distinct CorpContactFullName
From y
Order By 1">
</asp:SqlDataSource>
<asp:SqlDataSource ID="Models" runat="server" ConnectionString="<%$ ConnectionStrings:Bob %>" SelectCommand="Select Distinct CorpContactFullName
From z
Order By 1">
</asp:SqlDataSource>
</telerik:RadAjaxPanel>
</form>
</body>
BatchTest.cs:
protected void PropertyHistory_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
SavedChangesList.Visible = true;
}
protected void PropertyHistory_ItemUpdated(object source, GridUpdatedEventArgs e)
{
GridEditableItem item = (GridEditableItem)e.Item;
string id = item.GetDataKeyValue("RMCCHistoryID").ToString();
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
NotifyUser("ID " + id + " cannot be updated. Reason: " + e.Exception.Message);
}
else
NotifyUser("ID " + id + " is updated!");
}
protected void PropertyHistory_ItemInserted(object source, GridInsertedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
NotifyUser("Cannot be inserted. Reason: " + e.Exception.Message);
}
else
NotifyUser("New product is inserted!");
}
protected void PropertyHistory_ItemDeleted(object source, GridDeletedEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.Item;
string id = dataItem.GetDataKeyValue("RMCCHistoryID").ToString();
if (e.Exception != null)
{
e.ExceptionHandled = true;
NotifyUser("ID " + id + " cannot be deleted. Reason: " + e.Exception.Message);
}
else
NotifyUser("ID " + id + " is deleted!");
}
protected void PropertyHistory_PreRender(object sender, EventArgs e)
{
//RadNumericTextBox w = (PersonnelHistory.MasterTableView.GetBatchColumnEditor("UnitsInStock") as GridNumericColumnEditor).NumericTextBox;
//w.Width = Unit.Pixel(60);
//TextBox x = (PersonnelHistory.MasterTableView.GetBatchColumnEditor("QuantityPerUnit") as GridTextBoxColumnEditor).TextBoxControl;
//x.Width = Unit.Pixel(120);
}
]
private void NotifyUser(string message)
{
RadListBoxItem commandListItem = new RadListBoxItem();
commandListItem.Text = message;
SavedChangesList.Items.Add(commandListItem);
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PropertyHistories_Deleting(object sender, SqlDataSourceCommandEventArgs e)
{
// NOT BEING HIT!
var x = e;
}
protected void PropertyHistories_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
// NOT BEING HIT!
var x = e;
}
protected void PropertyHistories_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
// NOT BEING HIT!
var x = e;
}
It's ideal, because the users need to edit multiple rows and click save. The example does that with the Save Changes at the bottom. The down side is that I need to put in business logic on the create, update, and delete. Normally, I can do that, even with a SQLDataSource, using the SQLDataSource events (ex. PropertyHistories_Updating). The problem is that these events are not triggering.
Yes, I know that I could use Advanced Binding, but am unsure how this example would work with it. :)
Any ideas? (see attached)
Thanks,
Jason
Code:
BatchTest.aspx
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" HorizontalAlign="NotSet">
<p>Hotel Name: <telerik:RadComboBox ID="HotelList" Width="500" runat="server" DataSourceID="Hotels" DataTextField="myview"
AllowCustomText="false" Filter="StartsWith" ShowMoreResultsBox="true" DataValueField="Inncode" />
<p>
</p>
<h3>Property History</h3>
<telerik:RadGrid ID="PropertyHistory" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="PropertyHistories" OnBatchEditCommand="PropertyHistory_BatchEditCommand" OnItemDeleted="PersonnelHistory_ItemDeleted" OnItemInserted="PropertyHistory_ItemInserted" OnItemUpdated="PropertyHistory_ItemUpdated" OnPreRender="PropertyHistory_PreRender" Width="750px">
<MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Bottom" DataKeyNames="RMCCHistoryID" DataSourceID="PropertyHistories" EditMode="Batch">
<BatchEditingSettings EditType="Row" OpenEditingEvent="Click" />
<SortExpressions>
<telerik:GridSortExpression FieldName="RMCCHistoryID" SortOrder="Descending" />
</SortExpressions>
<Columns>
<telerik:GridTemplateColumn DataField="Model" HeaderText="RMCC Support Model" UniqueName="Class">
<ItemTemplate>
<%# Eval("Model") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="RadComboBox1" runat="server" AllowCustomText="false" DataSourceID="Models" DataTextField="Model" EmptyMessage="Search Models" EnableAutomaticLoadOnDemand="true" Filter="StartsWith" Height="200px" ShowMoreResultsBox="true" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Start Date" UniqueName="startdate">
<ItemTemplate>
<asp:Label ID="date" runat="server" Text='<%# Eval("startdate") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="picker1" runat="server" DbSelectedDate='<%# Bind("startdate") %>' MaxDate="12/31/2173" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="End Date" UniqueName="enddate">
<ItemTemplate>
<asp:Label ID="date" runat="server" Text='<%# Eval("enddate") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="picker1" runat="server" DbSelectedDate='<%# Bind("enddate") %>' MaxDate="12/31/2173" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ConfirmDialogType="RadWindow" ConfirmText="Are you sure you want to Delete?" ConfirmTitle="Delete" HeaderStyle-Width="50px" HeaderText="Delete" Text="Delete" UniqueName="DeleteColumn" />
</Columns>
</MasterTableView>
</telerik:RadGrid>
<p> </p>
<telerik:RadListBox ID="SavedChangesList1" runat="server" Height="200px" Visible="false" Width="600px">
</telerik:RadListBox>
<telerik:RadListBox ID="SavedChangesList" runat="server" Height="200px" Visible="false" Width="600px" />
<asp:SqlDataSource ID="PropertyHistories" runat="server" ConnectionString="<%$ ConnectionStrings:Bob %>" SelectCommand="spUAPPropertyHistory" SelectCommandType="StoredProcedure" DeleteCommand="spUAPPropertyHistoryDelete" DeleteCommandType="StoredProcedure" InsertCommand="spUAPPropertyHistoryInsert" InsertCommandType="StoredProcedure" UpdateCommand="spUAPPropertyHistoryUpdate" UpdateCommandType="StoredProcedure" OnDeleting="PropertyHistories_Deleting" OnInserting="PropertyHistories_Inserting" OnUpdating="PropertyHistories_Updating">
<DeleteParameters>
<asp:Parameter Name="RMCCHistoryID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="RMCCModelLvl2ID" Type="Int32" />
<asp:Parameter Name="RATPropID" Type="Int32" />
<asp:Parameter Name="StartDate" Type="String" />
<asp:Parameter Name="EndDate" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="HotelList" DefaultValue="ABC" Name="Inncode" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="RMCCHistoryID" Type="Int32" />
<asp:Parameter Name="RMCCModelLvl2ID" Type="Int32" />
<asp:Parameter Name="StartDate" Type="String" />
<asp:Parameter Name="EndDate" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="Hotels" runat="server" ConnectionString="<%$ ConnectionStrings:Bob %>" SelectCommand="Select Usename + ' - ' + Inncode as myview, Inncode
From x
Order by 1 Asc">
</asp:SqlDataSource>
<asp:SqlDataSource ID="Contacts" runat="server" ConnectionString="<%$ ConnectionStrings:Bob %>" SelectCommand="Select Distinct CorpContactFullName
From y
Order By 1">
</asp:SqlDataSource>
<asp:SqlDataSource ID="Models" runat="server" ConnectionString="<%$ ConnectionStrings:Bob %>" SelectCommand="Select Distinct CorpContactFullName
From z
Order By 1">
</asp:SqlDataSource>
</telerik:RadAjaxPanel>
</form>
</body>
BatchTest.cs:
protected void PropertyHistory_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
{
SavedChangesList.Visible = true;
}
protected void PropertyHistory_ItemUpdated(object source, GridUpdatedEventArgs e)
{
GridEditableItem item = (GridEditableItem)e.Item;
string id = item.GetDataKeyValue("RMCCHistoryID").ToString();
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
NotifyUser("ID " + id + " cannot be updated. Reason: " + e.Exception.Message);
}
else
NotifyUser("ID " + id + " is updated!");
}
protected void PropertyHistory_ItemInserted(object source, GridInsertedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
NotifyUser("Cannot be inserted. Reason: " + e.Exception.Message);
}
else
NotifyUser("New product is inserted!");
}
protected void PropertyHistory_ItemDeleted(object source, GridDeletedEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.Item;
string id = dataItem.GetDataKeyValue("RMCCHistoryID").ToString();
if (e.Exception != null)
{
e.ExceptionHandled = true;
NotifyUser("ID " + id + " cannot be deleted. Reason: " + e.Exception.Message);
}
else
NotifyUser("ID " + id + " is deleted!");
}
protected void PropertyHistory_PreRender(object sender, EventArgs e)
{
//RadNumericTextBox w = (PersonnelHistory.MasterTableView.GetBatchColumnEditor("UnitsInStock") as GridNumericColumnEditor).NumericTextBox;
//w.Width = Unit.Pixel(60);
//TextBox x = (PersonnelHistory.MasterTableView.GetBatchColumnEditor("QuantityPerUnit") as GridTextBoxColumnEditor).TextBoxControl;
//x.Width = Unit.Pixel(120);
}
]
private void NotifyUser(string message)
{
RadListBoxItem commandListItem = new RadListBoxItem();
commandListItem.Text = message;
SavedChangesList.Items.Add(commandListItem);
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PropertyHistories_Deleting(object sender, SqlDataSourceCommandEventArgs e)
{
// NOT BEING HIT!
var x = e;
}
protected void PropertyHistories_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
// NOT BEING HIT!
var x = e;
}
protected void PropertyHistories_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
// NOT BEING HIT!
var x = e;
}