or

<%= ... %> are missing around WindowBehaviors

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server">
</telerik:RadScriptManager>
<telerik:RadComboBox ID="RadComboBox1" runat="server" EnableLoadOnDemand="True">
</telerik:RadComboBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>
using System;
using Telerik.Web.UI;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
RadComboBox1.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(RadComboBox1_ItemsRequested);
}
void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
{
RadComboBox comboBox = (RadComboBox)sender;
comboBox.Items.Add(new RadComboBoxItem("Test"));
comboBox.Items.Add(new RadComboBoxItem("Test Test"));
comboBox.Items.Add(new RadComboBoxItem("Test Test2")); // note: 2 spaces
e.EndOfItems = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = RadComboBox1.Text.Replace(" ", ".");
}
}
| <telerik:RadGrid ID="RadGrid1" DataSourceID="SessionDataSource1" runat="server" Skin="Telerik" ShowStatusBar="true" |
| Width="95%" AutoGenerateColumns="False" PageSize="3" AllowSorting="True" AllowMultiRowSelection="False" |
| AllowPaging="True" GridLines="None" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" |
| OnItemUpdated="RadGrid1_ItemUpdated" OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted" OnInsertCommand="RadGrid1_InsertCommand"> |
| <PagerStyle Mode="NumericPages"></PagerStyle> |
| <MasterTableView DataSourceID="SessionDataSource1" DataKeyNames="point_id" AllowMultiColumnSorting="True" |
| Width="100%" CommandItemDisplay="Top" Name="Hotel"> |
| <DetailTables> |
| <%--level2 Services--%> |
| <telerik:GridTableView DataKeyNames="service_id" DataSourceID="SessionDataSource2" Width="100%" |
| runat="server" CommandItemDisplay="Top" Name="Services" AllowAutomaticInserts="true"> |
| <ParentTableRelation> |
| <telerik:GridRelationFields DetailKeyField="point_id" MasterKeyField="point_id" /> |
| </ParentTableRelation> |
| <DetailTables> |
| <%--level3 Rooms --%> |
| <telerik:GridTableView DataKeyNames="room_id" DataSourceID="SessionDataSource3" Width="100%" |
| runat="server" CommandItemDisplay="Top" Name="Rooms" AllowAutomaticInserts="true" > |
| <ParentTableRelation> |
| <telerik:GridRelationFields DetailKeyField="service_id" MasterKeyField="service_id" /> |
| </ParentTableRelation> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn1"> |
| <HeaderStyle Width="20px" /> |
| <ItemStyle CssClass="MyImageButton" /> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridBoundColumn SortExpression="room_id" HeaderText="Rooms" HeaderButtonType="TextButton" |
| DataField="room_id" UniqueName="room_id" ReadOnly="true" Visible="false"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn SortExpression="Price" HeaderText="UPrice" HeaderButtonType="TextButton" |
| DataField="Price" UniqueName="Price"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn SortExpression="PriceWE" HeaderText="PriceWE" HeaderButtonType="TextButton" |
| DataField="PriceWE" UniqueName="PriceWE"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn SortExpression="Discount" HeaderText="Discount" HeaderButtonType="TextButton" |
| DataField="Discount" UniqueName="Discount"> |
| </telerik:GridBoundColumn> |
| <telerik:GridButtonColumn ConfirmText="Delete this room?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn1"> |
| <HeaderStyle Width="20px" /> |
| <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| <SortExpressions> |
| <telerik:GridSortExpression FieldName="PriceWE" SortOrder="Descending"></telerik:GridSortExpression> |
| </SortExpressions> |
| </telerik:GridTableView> |
| </DetailTables> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn2"> |
| <HeaderStyle Width="20px" /> |
| <ItemStyle CssClass="MyImageButton" /> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridBoundColumn SortExpression="service_id" HeaderText="service_id" HeaderButtonType="TextButton" |
| DataField="service_id" UniqueName="service_id" ReadOnly="true"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn SortExpression="service_name" HeaderText="Service" HeaderButtonType="TextButton" |
| DataField="service_name" UniqueName="service_name" ReadOnly="true"> |
| </telerik:GridBoundColumn> |
| <telerik:GridButtonColumn ConfirmText="Delete this service?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn2"> |
| <HeaderStyle Width="20px" /> |
| <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| <SortExpressions> |
| <telerik:GridSortExpression FieldName="service_name"></telerik:GridSortExpression> |
| </SortExpressions> |
| </telerik:GridTableView> |
| </DetailTables> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"> |
| <HeaderStyle Width="20px" /> |
| <ItemStyle CssClass="MyImageButton" /> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridBoundColumn SortExpression="point_id" HeaderText="point_id" HeaderButtonType="TextButton" |
| DataField="point_id" UniqueName="point_id" ReadOnly="true"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn SortExpression="point_name" HeaderText="Name" HeaderButtonType="TextButton" |
| DataField="point_name" UniqueName="point_name"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn SortExpression="point_adress" HeaderText="Adress" HeaderButtonType="TextButton" |
| DataField="point_adress" UniqueName="point_adress"> |
| </telerik:GridBoundColumn> |
| <telerik:GridButtonColumn ConfirmText="Delete this hotel?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"> |
| <HeaderStyle Width="20px" /> |
| <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| <SortExpressions> |
| <telerik:GridSortExpression FieldName="point_adress"></telerik:GridSortExpression> |
| </SortExpressions> |
| </MasterTableView> |
| </telerik:RadGrid> |
| <%--DATASOURCES --%> |
| <asp:SqlDataSource ID="SessionDataSource1" ConnectionString="<%$ ConnectionStrings:MyProv %>" |
| ProviderName="<%$ ConnectionStrings:MyProv.ProviderName %>" |
| SelectCommand="SELECT * FROM loc_OnTrip" runat="server" |
| OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues"> |
| </asp:SqlDataSource> |
| <asp:SqlDataSource ID="SessionDataSource2" ConnectionString="<%$ ConnectionStrings:MyProv %>" |
| ProviderName="<%$ ConnectionStrings:MyProv.ProviderName %>" |
| SelectCommand="SELECT * FROM [loc_OnTrip_Service] Where point_id = @point_id" runat="server" |
| OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues" > |
| <SelectParameters> |
| <asp:Parameter Name="point_id" Type="string" /> |
| </SelectParameters> |
| </asp:SqlDataSource> |
| <asp:SqlDataSource ID="SessionDataSource3" ConnectionString="<%$ ConnectionStrings:MyProv%>" |
| ProviderName="<%$ ConnectionStrings:MyProv.ProviderName %>" |
| SelectCommand="SELECT * FROM [loc_OnTrip_Service_room] where service_id = @service_id" runat="server" |
| OldValuesParameterFormatString="original_{0}" ConflictDetection="CompareAllValues" > |
| <SelectParameters> |
| <asp:Parameter Name="service_id" Type="string" /> |
| </SelectParameters> |
| </asp:SqlDataSource> |
| <br /> |
| private void Page_Load(object sender, EventArgs e) |
| { |
| if (!IsPostBack) |
| { |
| //Setting Selected index prior to binding RadGrid: |
| //If the index is in detail table, parent items will be expanded |
| //automatically |
| RadGrid1.SelectedIndexes.Add(1, 0, 1, 0, 0); |
| //Index of 1, 0, 1, 0, 0 means: |
| //1 - item with index 1 in the MasterTabelView |
| //0 - detail table with index 0 |
| //1 - item with index 1 (the second item) in the first detail table |
| //0 - 0 the third-level detail table |
| //0 - the item with index 0 in the third-level table |
| } |
| } |
| protected void RadGrid1_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e) |
| { |
| string item = getItemName(e.Item.OwnerTableView.Name); |
| string field = getFieldName(e.Item.OwnerTableView.Name); |
| if (e.Exception != null) |
| { |
| e.KeepInEditMode = true; |
| e.ExceptionHandled = true; |
| DisplayMessage(item + " " + e.Item[field].Text + " cannot be updated. Reason: " + e.Exception.Message); |
| } |
| else |
| { |
| DisplayMessage(item + " " + e.Item[field].Text + " updated"); |
| } |
| } |
| protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e) |
| { |
| string item = getItemName(e.Item.OwnerTableView.Name); |
| if (e.Exception != null) |
| { |
| e.ExceptionHandled = true; |
| DisplayMessage(item + " cannot be inserted. Reason: " + e.Exception.Message); |
| } |
| else |
| { |
| DisplayMessage(item + " inserted"); |
| } |
| } |
| protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e) |
| { |
| string item = getItemName(e.Item.OwnerTableView.Name); |
| string field = getFieldName(e.Item.OwnerTableView.Name); |
| if (e.Exception != null) |
| { |
| e.ExceptionHandled = true; |
| DisplayMessage(item + " " + e.Item[field].Text + " cannot be deleted. Reason: " + e.Exception.Message); |
| } |
| else |
| { |
| DisplayMessage(item + " " + e.Item[field].Text + " deleted"); |
| } |
| } |
| protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| if ("Service".Equals(e.Item.OwnerTableView.Name)) |
| { |
| GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem; |
| SessionDataSource2.InsertParameters["point_id"].DefaultValue = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["point_id"].ToString(); |
| } |
| else if ("Rooms".Equals(e.Item.OwnerTableView.Name)) |
| { |
| GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem; |
| SessionDataSource3.InsertParameters["service_id"].DefaultValue = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["service_id"].ToString(); |
| } |
| } |
| /* Sample |
| protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| GridDataItem parentItem = e.Item.OwnerTableView.ParentItem as GridDataItem; |
| nestedTableSource.InsertParameters["EmployeeID"].DefaultValue = parentItem.OwnerTableView.DataKeyValues[parentItem.ItemIndex]["EmployeeID"].ToString(); |
| } |
| */ |
| private String getItemName(string tableName) |
| { |
| switch (tableName) |
| { |
| case ("Hotel"): |
| { |
| return "loc_Ontrip";// for Hotels |
| } |
| case ("Service"): |
| { |
| return "loc_OnTrip_Service";// for services |
| } |
| case ("Rooms"): |
| { |
| return "loc_OnTrip_Services_room"; // for Rooms |
| } |
| default: return ""; |
| } |
| } |
| private String getFieldName(string tableName) |
| { |
| switch (tableName) |
| { |
| case ("loc_Ontrip"): |
| { |
| return "point_id"; |
| } |
| case ("loc_OnTrip_Service"): |
| { |
| return "service_id"; |
| } |
| case ("loc_OnTrip_Services_room"): |
| { |
| return "room_id"; |
| } |
| default: return ""; |
| } |
| } |
| private void DisplayMessage(string text) |
| { |
| RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text))); |
| } |