Added more samples related to RadGrid

This commit is contained in:
Genady 2013-05-21 11:06:58 +03:00
Родитель ecae519938
Коммит e14043f589
33 изменённых файлов: 1150 добавлений и 0 удалений

14
ComboBox/ComboBox.sln Normal file
Просмотреть файл

@ -0,0 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{45D18724-1D09-4454-8AE0-65EA4FFD3473}"
ProjectSection(SolutionItems) = preProject
Readme.txt = Readme.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Двоичные данные
ComboBox/ComboBox.zip Normal file

Двоичный файл не отображается.

1
ComboBox/Readme.txt Normal file
Просмотреть файл

@ -0,0 +1 @@
Examples related to RadComboBox

14
Editor/Editor.sln Normal file
Просмотреть файл

@ -0,0 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6EAECC39-8EB3-4874-A83F-5E165DB6AE99}"
ProjectSection(SolutionItems) = preProject
Readme.txt = Readme.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Двоичные данные
Editor/Editor.zip Normal file

Двоичный файл не отображается.

1
Editor/Readme.txt Normal file
Просмотреть файл

@ -0,0 +1 @@
Examples related to RadEditor

Двоичные данные
Grid/ClientEditBatchUpdates/App_Data/Northwind.mdf Normal file

Двоичный файл не отображается.

Двоичные данные
Grid/ClientEditBatchUpdates/App_Data/Northwind_log.ldf Normal file

Двоичный файл не отображается.

Двоичные данные
Grid/ClientEditBatchUpdates/ClientEditBatchUpdates.zip Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,367 @@
<%@ Page Language="c#" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.GridExamplesCSharp.AJAX.ClientEditBatchUpdates.DefaultCS"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<html>
<head>
<title>Test</title>
<script type="text/javascript">
</script>
</head>
<body>
<form id="Form1" runat="server">
<telerik:RadScriptManager runat="server"></telerik:RadScriptManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
//<![CDATA[
//Custom js code section used to edit records, store changes and switch the visibility of column editors
//global variables for edited cell and edited rows ids
var editedCell;
var arrayIndex = 0;
var editedItemsIds = [];
function RowCreated(sender, eventArgs)
{
var dataItem = eventArgs.get_gridDataItem();
//traverse the cells in the created client row object and attach dblclick handler for each of them
for (var i = 1; i < dataItem.get_element().cells.length; i++)
{
var cell = dataItem.get_element().cells[i];
if (cell)
{
$addHandler(cell, "dblclick", Function.createDelegate(cell, ShowColumnEditor));
}
}
}
//detach the ondblclick handlers from the cells on row disposing
function RowDestroying(sender, eventArgs)
{
if (eventArgs.get_id() === "") return;
var row = eventArgs.get_gridDataItem().get_element();
var cells = row.cells;
for (var j = 0, len = cells.length; j < len; j++)
{
var cell = cells[j];
if (cell)
{
$clearHandlers(cell);
}
}
}
function RowClick(sender, eventArgs)
{
if (editedCell)
{
//if the click target is table cell or span and there is an edited cell, update the value in it
//skip update if clicking a span that happens to be a form decorator element (having a class that starts with "rfd")
if ((eventArgs.get_domEvent().target.tagName == "TD") ||
(eventArgs.get_domEvent().target.tagName == "SPAN" && !eventArgs.get_domEvent().target.className.startsWith("rfd")))
{
UpdateValues(sender);
editedCell = false;
}
}
}
function ShowColumnEditor()
{
editedCell = this;
//hide text and show column editor in the edited cell
var cellText = this.getElementsByTagName("span")[0];
cellText.style.display = "none";
//display the span which wrapps the hidden checkbox editor
if (this.getElementsByTagName("span")[1])
{
this.getElementsByTagName("span")[1].style.display = "";
}
var colEditor = this.getElementsByTagName("input")[0] || this.getElementsByTagName("select")[0];
//if the column editor is a form decorated select dropdown, show it instead of the original
if (colEditor.className == "rfdRealInput" && colEditor.tagName.toLowerCase() == "select") colEditor = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(colEditor);
colEditor.style.display = "";
colEditor.focus();
}
function StoreEditedItemId(editCell)
{
//get edited row key value and add it to the array which holds them
var gridRow = $find(editCell.parentNode.id);
var rowKeyValue = gridRow.getDataKeyValue("ProductID");
Array.add(editedItemsIds, rowKeyValue);
}
function HideEditor(editCell, editorType)
{
//get reference to the label in the edited cell
var lbl = editCell.getElementsByTagName("span")[0];
switch (editorType)
{
case "textbox":
var txtBox = editCell.getElementsByTagName("input")[0];
if (lbl.innerHTML != txtBox.value)
{
lbl.innerHTML = txtBox.value;
editCell.style.border = "1px dashed";
StoreEditedItemId(editCell);
}
txtBox.style.display = "none";
break;
case "checkbox":
var chkBox = editCell.getElementsByTagName("input")[0];
if (lbl.innerHTML.toLowerCase() != chkBox.checked.toString())
{
lbl.innerHTML = chkBox.checked;
editedCell.style.border = "1px dashed";
StoreEditedItemId(editCell);
}
chkBox.style.display = "none";
editCell.getElementsByTagName("span")[1].style.display = "none";
break;
case "dropdown":
var ddl = editCell.getElementsByTagName("select")[0];
var selectedValue = ddl.options[ddl.selectedIndex].value;
if (lbl.innerHTML != selectedValue)
{
lbl.innerHTML = selectedValue;
editCell.style.border = "1px dashed";
StoreEditedItemId(editCell);
}
//if the form decorator was enabled, hide the decorated dropdown instead of the original.
if (ddl.className == "rfdRealInput") ddl = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(ddl);
ddl.style.display = "none";
default:
break;
}
lbl.style.display = "inline";
}
function UpdateValues(grid)
{
//determine the name of the column to which the edited cell belongs
var tHeadElement = grid.get_element().getElementsByTagName("thead")[0];
var headerRow = tHeadElement.getElementsByTagName("tr")[0];
var colName = grid.get_masterTableView().getColumnUniqueNameByCellIndex(headerRow, editedCell.cellIndex);
//based on the column name, extract the value from the editor, update the text of the label and switch its visibility with that of the column
//column. The update happens only when the column editor value is different than the non-editable value. We also set dashed border to indicate
//that the value in the cell is changed. The logic is isolated in the HideEditor js method
switch (colName)
{
case "ProductName":
HideEditor(editedCell, "textbox");
break;
case "QuantityPerUnit":
HideEditor(editedCell, "textbox");
break;
case "UnitPrice":
HideEditor(editedCell, "textbox");
break;
case "UnitsInStock":
HideEditor(editedCell, "dropdown");
break;
case "UnitsOnOrder":
HideEditor(editedCell, "textbox");
break;
case "Discontinued":
HideEditor(editedCell, "checkbox");
break;
default:
break;
}
}
function CancelChanges()
{
if (editedItemsIds.length > 0)
{
$find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("");
}
else
{
alert("No pending changes to be discarded");
}
editedItemsIds = [];
}
function ProcessChanges()
{
//extract edited rows ids and pass them as argument in the ajaxRequest method of the manager
if (editedItemsIds.length > 0)
{
var Ids = "";
for (var i = 0; i < editedItemsIds.length; i++)
{
Ids = Ids + editedItemsIds[i] + ":";
}
$find("<%=RadAjaxManager1.ClientID %>").ajaxRequest(Ids);
}
else
{
alert("No pending changes to be processed");
}
editedItemsIds = [];
}
function RadGrid1_Command(sender, eventArgs)
{
//Note that this code has to be executed if you postback from external control instead from the grid (intercepting its onclientclick handler for this purpose),
//otherwise the edited values will be lost or not propagated in the source
if (editedItemsIds.length > 0)
{
if (eventArgs.get_commandName() == "Sort" || eventArgs.get_commandName() == "Page" || eventArgs.get_commandName() == "Filter")
{
if (confirm("Any unsaved edited values will be lost. Choose 'OK' to discard the changes before proceeding or 'Cancel' to abort the action and process them."))
{
editedItemsIds = [];
}
else
{
//cancel the chosen action
eventArgs.set_cancel(true);
//process the changes
ProcessChanges();
editedItemsIds = [];
}
}
}
}
//]]>
</script>
</telerik:RadCodeBlock>
<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="Default,Select,Textbox"
EnableRoundedCorners="false"></telerik:RadFormDecorator>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1">
</telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="RadInputManager1"></telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="Label1"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1">
</telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="RadInputManager1"></telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="Label1"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadInputManager ID="RadInputManager1" EnableEmbeddedBaseStylesheet="false"
Skin="" runat="server">
<telerik:TextBoxSetting BehaviorID="StringBehavior" InitializeOnClient="true" EmptyMessage="type here">
</telerik:TextBoxSetting>
<telerik:NumericTextBoxSetting BehaviorID="CurrencyBehavior" EmptyMessage="type.."
Type="Currency" Validation-IsRequired="true" MinValue="1" InitializeOnClient="true"
MaxValue="100000">
</telerik:NumericTextBoxSetting>
<telerik:NumericTextBoxSetting InitializeOnClient="true" BehaviorID="NumberBehavior"
EmptyMessage="type.." Type="Number" DecimalDigits="0" MinValue="0" MaxValue="100">
</telerik:NumericTextBoxSetting>
</telerik:RadInputManager>
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" Width="97%" ShowStatusBar="True"
AllowSorting="True" PageSize="15" GridLines="None" AllowPaging="True" runat="server"
AutoGenerateColumns="False" OnItemCreated="RadGrid1_ItemCreated">
<MasterTableView TableLayout="Fixed" DataKeyNames="ProductID" EditMode="InPlace"
ClientDataKeyNames="ProductID" CommandItemDisplay="Bottom">
<CommandItemTemplate>
<div style="height: 30px; text-align: right;">
<asp:Image ID="imgCancelChanges" runat="server" ImageUrl="~/Img/cancel.gif"
AlternateText="Cancel changes" ToolTip="Cancel changes" Height="24px" Style="cursor: pointer;
margin: 2px 5px 0px 0px;" onclick="CancelChanges();"></asp:Image>
<asp:Image ID="imgProcessChanges" runat="server" ImageUrl="~/Img/ok.gif"
AlternateText="Process changes" ToolTip="Process changes" Height="24px" Style="cursor: pointer;
margin: 2px 5px 0px 0px;" onclick="ProcessChanges();"></asp:Image>
</div>
</CommandItemTemplate>
<Columns>
<telerik:GridBoundColumn UniqueName="ProductID" DataField="ProductID" HeaderText="ProductID"
ReadOnly="True" HeaderStyle-Width="5%">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="ProductName" SortExpression="ProductName"
HeaderText="ProductName" HeaderStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
<asp:TextBox ID="txtBoxName" runat="server" Text='<%# Bind("ProductName") %>' Width="95%"
Style="display: none"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="QuantityPerUnit" HeaderText="QuantityPerUnit"
SortExpression="QuantityPerUnit" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblQuantityPerUnit" runat="server" Text='<%# Eval("QuantityPerUnit") %>'></asp:Label>
<asp:TextBox ID="txtQuantityPerUnit" runat="server" Text='<%# Bind("QuantityPerUnit") %>'
Width="95%" Style="display: none"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice"
HeaderStyle-Width="7%">
<ItemTemplate>
<asp:Label ID="lblUnitPrice" runat="server" Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>
<asp:TextBox ID="txtUnitPrice" runat="server" Width="95%" Text='<%# Bind("UnitPrice") %>'
Style="display: none"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock"
HeaderStyle-Width="8%">
<ItemTemplate>
<asp:Label ID="lblUnitsInStock" runat="server" Text='<%# Eval("UnitsInStock") %>'></asp:Label>
<asp:DropDownList ID="ddlUnitsInStock" runat="server" DataTextField="UnitsInStock"
DataValueField="UnitsInStock" DataSourceID="SqlDataSource2" SelectedValue='<%# Bind("UnitsInStock") %>'
Style="display: none">
</asp:DropDownList>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder"
HeaderStyle-Width="7%">
<ItemTemplate>
<asp:Label ID="lblUnitsOnOrder" runat="server" Text='<%# Eval("UnitsOnOrder") %>'></asp:Label>
<asp:TextBox ID="txtUnitsOnOrder" runat="server" Text='<%# Bind("UnitsOnOrder") %>'
Width="95%" Style="display: none"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued"
HeaderStyle-Width="6%">
<ItemTemplate>
<asp:Label ID="lblDiscontinued" runat="server" Text='<%# Eval("Discontinued") %>'></asp:Label>
<asp:CheckBox ID="chkBoxDiscontinued" runat="server" Checked='<%# Bind("Discontinued") %>'
Style="display: none"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowCreated="RowCreated" OnRowClick="RowClick" OnCommand="RadGrid1_Command"
OnRowDestroying="RowDestroying"></ClientEvents>
</ClientSettings>
</telerik:RadGrid>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="false"></asp:Label>
<br />
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Products]"
runat="server" UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [QuantityPerUnit] = @QuantityPerUnit, [UnitPrice] = @UnitPrice, [UnitsInStock] = @UnitsInStock, [UnitsOnOrder] = @UnitsOnOrder, [Discontinued] = @Discontinued WHERE [ProductID] = @ProductID">
<UpdateParameters>
<asp:Parameter Name="ProductID" Type="Int16"></asp:Parameter>
<asp:Parameter Name="ProductName" Type="String"></asp:Parameter>
<asp:Parameter Name="QuantityPerUnit" Type="String"></asp:Parameter>
<asp:Parameter Name="UnitPrice" Type="Decimal"></asp:Parameter>
<asp:Parameter Name="UnitsInStock" Type="Int16"></asp:Parameter>
<asp:Parameter Name="UnitsOnOrder" Type="Int16"></asp:Parameter>
<asp:Parameter Name="Discontinued" Type="Boolean"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT UnitsInStock FROM [Products]">
</asp:SqlDataSource>
</form></body></html>

Просмотреть файл

@ -0,0 +1,89 @@
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
namespace Telerik.GridExamplesCSharp.AJAX.ClientEditBatchUpdates
{
public partial class DefaultCS : System.Web.UI.Page
{
private void SetMessage(string message)
{
Label1.Text = string.Format("<span>{0}</span>", message);
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
TextBox txtBox = (TextBox)dataItem.FindControl("txtBoxName");
TextBoxSetting stringSetting = (TextBoxSetting)RadInputManager1.GetSettingByBehaviorID("StringBehavior");
stringSetting.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));
txtBox = (TextBox)dataItem.FindControl("txtQuantityPerUnit");
stringSetting.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));
txtBox = (TextBox)dataItem.FindControl("txtUnitPrice");
NumericTextBoxSetting currencySetting = (NumericTextBoxSetting)RadInputManager1.GetSettingByBehaviorID("CurrencyBehavior");
currencySetting.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));
txtBox = (TextBox)dataItem.FindControl("txtUnitsOnOrder");
NumericTextBoxSetting numericSetting = (NumericTextBoxSetting)RadInputManager1.GetSettingByBehaviorID("NumberBehavior");
numericSetting.TargetControls.Add(new TargetInput(txtBox.UniqueID, true));
}
}
protected void RadAjaxManager1_AjaxRequest(object sender, Web.UI.AjaxRequestEventArgs e)
{
if (e.Argument == string.Empty)
{
RadGrid1.Rebind();
}
string[] editedItemIds = e.Argument.Split(':');
int i;
for (i = 0; i <= editedItemIds.Length - 2; i++)
{
string productId = editedItemIds[i];
GridDataItem updatedItem = RadGrid1.MasterTableView.FindItemByKeyValue("ProductID", int.Parse(productId));
UpdateValues(updatedItem);
}
}
protected void UpdateValues(GridDataItem updatedItem)
{
TextBox txtBox = (TextBox)updatedItem.FindControl("txtBoxName");
SqlDataSource1.UpdateParameters["ProductName"].DefaultValue = txtBox.Text;
txtBox = (TextBox)updatedItem.FindControl("txtQuantityPerUnit");
SqlDataSource1.UpdateParameters["QuantityPerUnit"].DefaultValue = txtBox.Text;
txtBox = (TextBox)updatedItem.FindControl("txtUnitPrice");
SqlDataSource1.UpdateParameters["UnitPrice"].DefaultValue = txtBox.Text;
txtBox = (TextBox)updatedItem.FindControl("txtUnitsOnOrder");
SqlDataSource1.UpdateParameters["UnitsOnOrder"].DefaultValue = txtBox.Text;
DropDownList ddl = (DropDownList)updatedItem.FindControl("ddlUnitsInStock");
SqlDataSource1.UpdateParameters["UnitsInStock"].DefaultValue = ddl.SelectedValue;
CheckBox chkBox = (CheckBox)updatedItem.FindControl("chkBoxDiscontinued");
SqlDataSource1.UpdateParameters["Discontinued"].DefaultValue = chkBox.Checked.ToString();
SqlDataSource1.UpdateParameters["ProductID"].DefaultValue = updatedItem.GetDataKeyValue("ProductID").ToString();
try
{
SqlDataSource1.Update();
}
catch (Exception ex)
{
SetMessage(Server.HtmlEncode("Unable to update Products. Reason: " + ex.StackTrace).Replace("'", "&#39;").Replace("\r\n", "<br />"));
}
SetMessage("Product with ID: " + updatedItem.GetDataKeyValue("ProductID") + " updated");
}
}
}

Просмотреть файл

@ -0,0 +1,347 @@
<%@ Page Language="vb" CodeFile="DefaultVB.aspx.vb" Inherits="Telerik.GridExamplesVBNET.AJAX.ClientEditBatchUpdates.DefaultVB" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<html>
<head>
<title>Test</title>
<script type="text/javascript">
</script>
</head>
<body>
<form id="Form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
//<![CDATA[
//Custom js code section used to edit records, store changes and switch the visibility of column editors
//global variables for edited cell and edited rows ids
var editedCell;
var arrayIndex = 0;
var editedItemsIds = [];
function RowCreated(sender, eventArgs) {
var dataItem = eventArgs.get_gridDataItem();
//traverse the cells in the created client row object and attach dblclick handler for each of them
for (var i = 1; i < dataItem.get_element().cells.length; i++) {
var cell = dataItem.get_element().cells[i];
if (cell) {
$addHandler(cell, "dblclick", Function.createDelegate(cell, ShowColumnEditor));
}
}
}
//detach the ondblclick handlers from the cells on row disposing
function RowDestroying(sender, eventArgs) {
if (eventArgs.get_id() === "") return;
var row = eventArgs.get_gridDataItem().get_element();
var cells = row.cells;
for (var j = 0, len = cells.length; j < len; j++) {
var cell = cells[j];
if (cell) {
$clearHandlers(cell);
}
}
}
function RowClick(sender, eventArgs) {
if (editedCell) {
//if the click target is table cell or span and there is an edited cell, update the value in it
//skip update if clicking a span that happens to be a form decorator element (having a class that starts with "rfd")
if ((eventArgs.get_domEvent().target.tagName == "TD") ||
(eventArgs.get_domEvent().target.tagName == "SPAN" && !eventArgs.get_domEvent().target.className.startsWith("rfd"))) {
UpdateValues(sender);
editedCell = false;
}
}
}
function ShowColumnEditor() {
editedCell = this;
//hide text and show column editor in the edited cell
var cellText = this.getElementsByTagName("span")[0];
cellText.style.display = "none";
//display the span which wrapps the hidden checkbox editor
if (this.getElementsByTagName("span")[1]) {
this.getElementsByTagName("span")[1].style.display = "";
}
var colEditor = this.getElementsByTagName("input")[0] || this.getElementsByTagName("select")[0];
//if the column editor is a form decorated select dropdown, show it instead of the original
if (colEditor.className == "rfdRealInput" && colEditor.tagName.toLowerCase() == "select") colEditor = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(colEditor);
colEditor.style.display = "";
colEditor.focus();
}
function StoreEditedItemId(editCell) {
//get edited row key value and add it to the array which holds them
var gridRow = $find(editCell.parentNode.id);
var rowKeyValue = gridRow.getDataKeyValue("ProductID");
Array.add(editedItemsIds, rowKeyValue);
}
function HideEditor(editCell, editorType) {
//get reference to the label in the edited cell
var lbl = editCell.getElementsByTagName("span")[0];
switch (editorType) {
case "textbox":
var txtBox = editCell.getElementsByTagName("input")[0];
if (lbl.innerHTML != txtBox.value) {
lbl.innerHTML = txtBox.value;
editCell.style.border = "1px dashed";
StoreEditedItemId(editCell);
}
txtBox.style.display = "none";
break;
case "checkbox":
var chkBox = editCell.getElementsByTagName("input")[0];
if (lbl.innerHTML.toLowerCase() != chkBox.checked.toString()) {
lbl.innerHTML = chkBox.checked;
editedCell.style.border = "1px dashed";
StoreEditedItemId(editCell);
}
chkBox.style.display = "none";
editCell.getElementsByTagName("span")[1].style.display = "none";
break;
case "dropdown":
var ddl = editCell.getElementsByTagName("select")[0];
var selectedValue = ddl.options[ddl.selectedIndex].value;
if (lbl.innerHTML != selectedValue) {
lbl.innerHTML = selectedValue;
editCell.style.border = "1px dashed";
StoreEditedItemId(editCell);
}
//if the form decorator was enabled, hide the decorated dropdown instead of the original.
if (ddl.className == "rfdRealInput") ddl = Telerik.Web.UI.RadFormDecorator.getDecoratedElement(ddl);
ddl.style.display = "none";
default:
break;
}
lbl.style.display = "inline";
}
function UpdateValues(grid) {
//determine the name of the column to which the edited cell belongs
var tHeadElement = grid.get_element().getElementsByTagName("thead")[0];
var headerRow = tHeadElement.getElementsByTagName("tr")[0];
var colName = grid.get_masterTableView().getColumnUniqueNameByCellIndex(headerRow, editedCell.cellIndex);
//based on the column name, extract the value from the editor, update the text of the label and switch its visibility with that of the column
//column. The update happens only when the column editor value is different than the non-editable value. We also set dashed border to indicate
//that the value in the cell is changed. The logic is isolated in the HideEditor js method
switch (colName) {
case "ProductName":
HideEditor(editedCell, "textbox");
break;
case "QuantityPerUnit":
HideEditor(editedCell, "textbox");
break;
case "UnitPrice":
HideEditor(editedCell, "textbox");
break;
case "UnitsInStock":
HideEditor(editedCell, "dropdown");
break;
case "UnitsOnOrder":
HideEditor(editedCell, "textbox");
break;
case "Discontinued":
HideEditor(editedCell, "checkbox");
break;
default:
break;
}
}
function CancelChanges() {
if (editedItemsIds.length > 0) {
$find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("");
}
else {
alert("No pending changes to be discarded");
}
editedItemsIds = [];
}
function ProcessChanges() {
//extract edited rows ids and pass them as argument in the ajaxRequest method of the manager
if (editedItemsIds.length > 0) {
var Ids = "";
for (var i = 0; i < editedItemsIds.length; i++) {
Ids = Ids + editedItemsIds[i] + ":";
}
$find("<%=RadAjaxManager1.ClientID %>").ajaxRequest(Ids);
}
else {
alert("No pending changes to be processed");
}
editedItemsIds = [];
}
function RadGrid1_Command(sender, eventArgs) {
//Note that this code has to be executed if you postback from external control instead from the grid (intercepting its onclientclick handler for this purpose),
//otherwise the edited values will be lost or not propagated in the source
if (editedItemsIds.length > 0) {
if (eventArgs.get_commandName() == "Sort" || eventArgs.get_commandName() == "Page" || eventArgs.get_commandName() == "Filter") {
if (confirm("Any unsaved edited values will be lost. Choose 'OK' to discard the changes before proceeding or 'Cancel' to abort the action and process them.")) {
editedItemsIds = [];
}
else {
//cancel the chosen action
eventArgs.set_cancel(true);
//process the changes
ProcessChanges();
editedItemsIds = [];
}
}
}
}
window.onunload = function () {
//this code should also be executed on postback from external control (which rebinds the grid) to process any unsaved data
if (editedItemsIds.length > 0) {
if (confirm("Any unsaved edited values will be lost. Choose 'OK' to discard the changes before proceeding or 'Cancel' to abort the action and process them.")) {
editedItemsIds = [];
}
else {
//process the changes
ProcessChanges();
editedItemsIds = [];
}
}
};
//]]>
</script>
</telerik:RadCodeBlock>
<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="Default,Select,Textbox"
EnableRoundedCorners="false"></telerik:RadFormDecorator>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="RadInputManager1"></telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="Label1"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="RadInputManager1"></telerik:AjaxUpdatedControl>
<telerik:AjaxUpdatedControl ControlID="Label1"></telerik:AjaxUpdatedControl>
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadInputManager ID="RadInputManager1" EnableEmbeddedBaseStylesheet="false"
Skin="" runat="server">
<telerik:TextBoxSetting BehaviorID="StringBehavior" InitializeOnClient="true" EmptyMessage="type here">
</telerik:TextBoxSetting>
<telerik:NumericTextBoxSetting BehaviorID="CurrencyBehavior" InitializeOnClient="true"
EmptyMessage="type.." Type="Currency" Validation-IsRequired="true" MinValue="1"
MaxValue="100000">
</telerik:NumericTextBoxSetting>
<telerik:NumericTextBoxSetting BehaviorID="NumberBehavior" InitializeOnClient="true"
EmptyMessage="type.." Type="Number" DecimalDigits="0" MinValue="0" MaxValue="100">
</telerik:NumericTextBoxSetting>
</telerik:RadInputManager>
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" Width="97%" ShowStatusBar="True"
AllowSorting="True" PageSize="15" GridLines="None" AllowPaging="True" runat="server"
AutoGenerateColumns="False">
<MasterTableView TableLayout="Fixed" DataKeyNames="ProductID" EditMode="InPlace"
ClientDataKeyNames="ProductID" CommandItemDisplay="Bottom">
<CommandItemTemplate>
<div style="height: 30px; text-align: right;">
<asp:Image ID="imgCancelChanges" runat="server" ImageUrl="~/Img/cancel.gif"
AlternateText="Cancel changes" ToolTip="Cancel changes" Height="24px" Style="cursor: pointer; margin: 2px 5px 0px 0px;"
onclick="CancelChanges();"></asp:Image>
<asp:Image ID="imgProcessChanges" runat="server" ImageUrl="~/Img/ok.gif"
AlternateText="Process changes" ToolTip="Process changes" Height="24px" Style="cursor: pointer; margin: 2px 5px 0px 0px;"
onclick="ProcessChanges();"></asp:Image>
</div>
</CommandItemTemplate>
<Columns>
<telerik:GridBoundColumn UniqueName="ProductID" DataField="ProductID" HeaderText="ProductID"
ReadOnly="True" HeaderStyle-Width="5%">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn UniqueName="ProductName" SortExpression="ProductName"
HeaderText="ProductName" HeaderStyle-Width="15%">
<ItemTemplate>
<asp:Label ID="lblProductName" runat="server" Text='<%# Eval("ProductName") %>'></asp:Label>
<asp:TextBox ID="txtBoxName" runat="server" Text='<%# Bind("ProductName") %>' Width="95%"
Style="display: none"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="QuantityPerUnit" HeaderText="QuantityPerUnit"
SortExpression="QuantityPerUnit" HeaderStyle-Width="10%">
<ItemTemplate>
<asp:Label ID="lblQuantityPerUnit" runat="server" Text='<%# Eval("QuantityPerUnit") %>'></asp:Label>
<asp:TextBox ID="txtQuantityPerUnit" runat="server" Text='<%# Bind("QuantityPerUnit") %>'
Width="95%" Style="display: none"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="UnitPrice" HeaderText="UnitPrice" SortExpression="UnitPrice"
HeaderStyle-Width="7%">
<ItemTemplate>
<asp:Label ID="lblUnitPrice" runat="server" Text='<%# Eval("UnitPrice", "{0:C}") %>'></asp:Label>
<asp:TextBox ID="txtUnitPrice" runat="server" Width="95%" Text='<%# Bind("UnitPrice") %>'
Style="display: none"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="UnitsInStock" HeaderText="UnitsInStock" SortExpression="UnitsInStock"
HeaderStyle-Width="8%">
<ItemTemplate>
<asp:Label ID="lblUnitsInStock" runat="server" Text='<%# Eval("UnitsInStock") %>'></asp:Label>
<asp:DropDownList ID="ddlUnitsInStock" runat="server" DataTextField="UnitsInStock"
DataValueField="UnitsInStock" DataSourceID="SqlDataSource2" SelectedValue='<%# Bind("UnitsInStock") %>'
Style="display: none">
</asp:DropDownList>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="UnitsOnOrder" HeaderText="UnitsOnOrder" SortExpression="UnitsOnOrder"
HeaderStyle-Width="7%">
<ItemTemplate>
<asp:Label ID="lblUnitsOnOrder" runat="server" Text='<%# Eval("UnitsOnOrder") %>'></asp:Label>
<asp:TextBox ID="txtUnitsOnOrder" runat="server" Text='<%# Bind("UnitsOnOrder") %>'
Width="95%" Style="display: none"></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn UniqueName="Discontinued" HeaderText="Discontinued" SortExpression="Discontinued"
HeaderStyle-Width="6%">
<ItemTemplate>
<asp:Label ID="lblDiscontinued" runat="server" Text='<%# Eval("Discontinued") %>'></asp:Label>
<asp:CheckBox ID="chkBoxDiscontinued" runat="server" Checked='<%# Bind("Discontinued") %>'
Style="display: none"></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowCreated="RowCreated" OnRowClick="RowClick" OnCommand="RadGrid1_Command"
OnRowDestroying="RowDestroying"></ClientEvents>
</ClientSettings>
</telerik:RadGrid>
<br />
<asp:Label ID="Label1" runat="server" EnableViewState="false"></asp:Label>
<br />
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Products]"
runat="server" UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [QuantityPerUnit] = @QuantityPerUnit, [UnitPrice] = @UnitPrice, [UnitsInStock] = @UnitsInStock, [UnitsOnOrder] = @UnitsOnOrder, [Discontinued] = @Discontinued WHERE [ProductID] = @ProductID">
<UpdateParameters>
<asp:Parameter Name="ProductID" Type="Int16"></asp:Parameter>
<asp:Parameter Name="ProductName" Type="String"></asp:Parameter>
<asp:Parameter Name="QuantityPerUnit" Type="String"></asp:Parameter>
<asp:Parameter Name="UnitPrice" Type="Decimal"></asp:Parameter>
<asp:Parameter Name="UnitsInStock" Type="Int16"></asp:Parameter>
<asp:Parameter Name="UnitsOnOrder" Type="Int16"></asp:Parameter>
<asp:Parameter Name="Discontinued" Type="Boolean"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT UnitsInStock FROM [Products]"></asp:SqlDataSource>
</form>
</body>
</html>

Просмотреть файл

@ -0,0 +1,78 @@
Imports System
Imports Telerik.Web.UI
Imports System.Collections
Namespace Telerik.GridExamplesVBNET.AJAX.ClientEditBatchUpdates
Partial Public MustInherit Class DefaultVB
Inherits System.Web.UI.Page
Private Sub SetMessage(ByVal message As String)
Label1.Text = String.Format("<span>{0}</span>", message)
End Sub
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated
If TypeOf e.Item Is GridDataItem Then
Dim dataItem As GridDataItem = CType(e.Item, GridDataItem)
Dim txtBox As TextBox = CType(dataItem.FindControl("txtBoxName"), TextBox)
Dim stringSetting As TextBoxSetting = DirectCast(RadInputManager1.GetSettingByBehaviorID("StringBehavior"), TextBoxSetting)
stringSetting.TargetControls.Add(New TargetInput(txtBox.UniqueID, True))
txtBox = CType(dataItem.FindControl("txtQuantityPerUnit"), TextBox)
stringSetting.TargetControls.Add(New TargetInput(txtBox.UniqueID, True))
txtBox = CType(dataItem.FindControl("txtUnitPrice"), TextBox)
Dim currencySetting As NumericTextBoxSetting = DirectCast(RadInputManager1.GetSettingByBehaviorID("CurrencyBehavior"), NumericTextBoxSetting)
currencySetting.TargetControls.Add(New TargetInput(txtBox.UniqueID, True))
txtBox = CType(dataItem.FindControl("txtUnitsOnOrder"), TextBox)
Dim numericSetting As NumericTextBoxSetting = DirectCast(RadInputManager1.GetSettingByBehaviorID("NumberBehavior"), NumericTextBoxSetting)
numericSetting.TargetControls.Add(New TargetInput(txtBox.UniqueID, True))
End If
End Sub
Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest
If e.Argument = String.Empty Then
RadGrid1.Rebind()
End If
Dim editedItemIds As String() = e.Argument.Split(":")
Dim i As Integer
For i = 0 To editedItemIds.Length - 2
Dim productId As String = editedItemIds(i)
Dim updatedItem As GridDataItem = RadGrid1.MasterTableView.FindItemByKeyValue("ProductID", Integer.Parse(productId))
UpdateValues(updatedItem)
Next
End Sub
Protected Sub UpdateValues(ByVal updatedItem As GridDataItem)
Dim txtBox As TextBox = CType(updatedItem.FindControl("txtBoxName"), TextBox)
SqlDataSource1.UpdateParameters("ProductName").DefaultValue = txtBox.Text
txtBox = CType(updatedItem.FindControl("txtQuantityPerUnit"), TextBox)
SqlDataSource1.UpdateParameters("QuantityPerUnit").DefaultValue = txtBox.Text
txtBox = CType(updatedItem.FindControl("txtUnitPrice"), TextBox)
SqlDataSource1.UpdateParameters("UnitPrice").DefaultValue = txtBox.Text
txtBox = CType(updatedItem.FindControl("txtUnitsOnOrder"), TextBox)
SqlDataSource1.UpdateParameters("UnitsOnOrder").DefaultValue = txtBox.Text
Dim ddl As DropDownList = CType(updatedItem.FindControl("ddlUnitsInStock"), DropDownList)
SqlDataSource1.UpdateParameters("UnitsInStock").DefaultValue = ddl.SelectedValue
Dim chkBox As CheckBox = CType(updatedItem.FindControl("chkBoxDiscontinued"), CheckBox)
SqlDataSource1.UpdateParameters("Discontinued").DefaultValue = chkBox.Checked
SqlDataSource1.UpdateParameters("ProductID").DefaultValue = updatedItem.GetDataKeyValue("ProductID").ToString()
Try
SqlDataSource1.Update()
Catch ex As Exception
SetMessage(Server.HtmlEncode("Unable to update Products. Reason: " + ex.StackTrace).Replace("'", "&#39;").Replace(vbCrLf, "<br />"))
End Try
SetMessage("Product with ID: " & updatedItem.GetDataKeyValue("ProductID") & " updated")
End Sub
End Class
End Namespace

Двоичные данные
Grid/ClientEditBatchUpdates/Img/cancel.gif Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 331 B

Двоичные данные
Grid/ClientEditBatchUpdates/Img/cancel.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 472 B

Двоичные данные
Grid/ClientEditBatchUpdates/Img/ok.gif Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 331 B

Двоичные данные
Grid/ClientEditBatchUpdates/Img/ok.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 460 B

Просмотреть файл

@ -0,0 +1,5 @@
The following example demonstrates how you can switch grid cells in edit mode by simply double-clicking
them, update the data on the client and then process
all changes on the server with a single batch update. This demo illustrates how
this can be accomplished using client scripts. Note that this approach is obsolete as the functionality
mentioned is now built-in.

Просмотреть файл

@ -0,0 +1,18 @@
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="NorthwindConnectionString35" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\Northwind.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation debug="false" targetFramework="4.0" />
<httpHandlers>
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
</httpHandlers>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
</handlers>
</system.webServer>
</configuration>

Просмотреть файл

@ -0,0 +1,4 @@
This example demonstrates how to export the RadGrid directly on server. From the dropdown list you could choose the export file type and by
clicking on the generate file button the corresponding file will be exported on the servet.
When a file does not exist on the server the download buttons will not be visible. If there is already exported file you could choose
whether you want to download the file or open it inside the browser.

Двоичные данные
Grid/GridExportGroupedData/App_Data/Northwind.mdf Normal file

Двоичный файл не отображается.

Двоичные данные
Grid/GridExportGroupedData/App_Data/Northwind_Log.ldf Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,60 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="RadGridBiffExport" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
<script type="text/javascript">
function onRequestStart(sender, args) {
if (args.get_eventTarget().indexOf("btnExport") >= 0)
args.set_enableAjax(false);
}
</script>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" ClientEvents-OnRequestStart="onRequestStart">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<asp:ImageButton ImageUrl="img/file-extension-xls-biff-icon.png" ID="ExportButtonTop" OnClick="ExportButton_Click" runat="server" />
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" ShowGroupPanel="true"
AllowPaging="true" PageSize="10">
<ExportSettings Excel-Format="Biff" ExportOnlyData="true" OpenInNewWindow="true"></ExportSettings>
<MasterTableView>
<GroupByExpressions>
<telerik:GridGroupByExpression>
<GroupByFields>
<telerik:GridGroupByField FieldName="City" HeaderText="City" />
</GroupByFields>
<SelectFields>
<telerik:GridGroupByField FieldName="City" HeaderText="City" />
</SelectFields>
</telerik:GridGroupByExpression>
</GroupByExpressions>
<Columns>
<telerik:GridBoundColumn DataField="CompanyName" HeaderText="Company Name" UniqueName="CompanyName"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ContactName" HeaderText="Contact Name" UniqueName="ContactName"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Address" HeaderText="Address" UniqueName="Address"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="City" HeaderText="City" UniqueName="City"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" UniqueName="Phone"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="Country" HeaderText="Country" UniqueName="Country"></telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowDragToGroup="true">
</ClientSettings>
</telerik:RadGrid>
<asp:ImageButton ImageUrl="img/file-extension-xls-biff-icon.png" ID="ExportButtonBottom" OnClick="ExportButton_Click" runat="server" />
<asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Customers"
runat="server"></asp:SqlDataSource>
</form>
</body>
</html>

Просмотреть файл

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using xls = Telerik.Web.UI.ExportInfrastructure;
using Telerik.Web.UI;
public partial class RadGridBiffExport : System.Web.UI.Page
{
private xls.Table table = new xls.Table();
private int row = 1;
private int currentHeaderItemIndex = 0;
protected void ExportButton_Click(object sender, ImageClickEventArgs e)
{
RadGrid1.CurrentPageIndex = 0;
RadGrid1.AllowPaging = false;
RadGrid1.Rebind();
TraverseGridStructure();
ExportGrid();
}
private void TraverseGridStructure()
{
GridHeaderItem headers = RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0] as GridHeaderItem;
int startIndex = RadGrid1.MasterTableView.GroupByExpressions.Count + 2;
for (int i = startIndex; i < headers.Cells.Count; i++)
{
table.Cells[i - 1, row].Value = headers.Cells[i].Text;
}
row++;
GridItem[] headerCollection = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader);
foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
{
string[] groupIndexArray = item.GroupIndex.Split('_');
TraverseHeaderItems(headerCollection, groupIndexArray);
for (int i = groupIndexArray.Length + 1; i < item.Controls.Count; i++)
{
table.Cells[i - 1, row].Value = (item.Controls[i] as GridTableCell).Text;
}
row++;
}
}
private void TraverseHeaderItems(GridItem[] headerCollection, string[] groupIndexArray)
{
if (currentHeaderItemIndex == headerCollection.Length)
{
return;
}
string[] headerIndex = headerCollection[currentHeaderItemIndex].GroupIndex.Split('_');
for (int j = 0; j < headerIndex.Length; j++)
{
if (headerIndex[j] != groupIndexArray[j])
{
return;
}
}
GridGroupHeaderItem currentHeaderItem = headerCollection[currentHeaderItemIndex] as GridGroupHeaderItem;
table.Cells[headerIndex.Length, row].Value = currentHeaderItem.DataCell.Text;
currentHeaderItemIndex++;
row++;
TraverseHeaderItems(headerCollection, groupIndexArray);
}
private void ExportGrid()
{
xls.ExportStructure structure = new xls.ExportStructure();
structure.Tables.Add(table);
xls.XlsBiffRenderer renderer = new xls.XlsBiffRenderer(structure);
byte[] renderedBytes = renderer.Render();
Response.Clear();
Response.AppendHeader("Content-Disposition:", "attachment; filename=ExportFile.xls");
Response.ContentType = "application/vnd.ms-excel";
Response.BinaryWrite(renderedBytes);
Response.End();
}
}

Двоичные данные
Grid/GridExportGroupedData/GridExportGroupedData.zip Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1 @@
This example demonstrates the ability to export grouped data when Biff export format is used.

Двоичные данные
Grid/GridExportGroupedData/img/file-extension-xls-biff-icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.4 KiB

Просмотреть файл

@ -0,0 +1,43 @@
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="NorthwindConnectionString" connectionString="Data Source=.\SQLSERVER2008R2;Initial Catalog=NORTHWIND;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<appSettings>
<add key="Telerik.ScriptManager.TelerikCdn" value="Disabled"/>
<add key="Telerik.StyleSheetManager.TelerikCdn" value="Disabled"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<pages>
<controls>
<add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI"/>
</controls>
</pages>
<httpHandlers>
<add path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler" verb="*" validate="false"/>
<add path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" validate="false"/>
<add path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" verb="*" validate="false"/>
<add path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" verb="*" validate="false"/>
<add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false"/>
</httpHandlers>
<httpModules/>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<handlers>
<remove name="ChartImage_axd"/>
<add name="ChartImage_axd" path="ChartImage.axd" type="Telerik.Web.UI.ChartHttpHandler" verb="*" preCondition="integratedMode"/>
<remove name="Telerik_Web_UI_SpellCheckHandler_axd"/>
<add name="Telerik_Web_UI_SpellCheckHandler_axd" path="Telerik.Web.UI.SpellCheckHandler.axd" type="Telerik.Web.UI.SpellCheckHandler" verb="*" preCondition="integratedMode"/>
<remove name="Telerik_Web_UI_DialogHandler_aspx"/>
<add name="Telerik_Web_UI_DialogHandler_aspx" path="Telerik.Web.UI.DialogHandler.aspx" type="Telerik.Web.UI.DialogHandler" verb="*" preCondition="integratedMode"/>
<remove name="Telerik_RadUploadProgressHandler_ashx"/>
<add name="Telerik_RadUploadProgressHandler_ashx" path="Telerik.RadUploadProgressHandler.ashx" type="Telerik.Web.UI.RadUploadProgressHandler" verb="*" preCondition="integratedMode"/>
<remove name="Telerik_Web_UI_WebResource_axd"/>
<add name="Telerik_Web_UI_WebResource_axd" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" preCondition="integratedMode"/>
</handlers>
</system.webServer>
</configuration>

Просмотреть файл

@ -0,0 +1,3 @@
This example demonstrates how to persist the selected items in a hierarchical RadGrid.When all items on a particular level are selected the parent item should also be selected.
If one of the items on the level is not selected the parent item should not be selected as well.
In order for the algorithm to work correctly each GridTableView should have DataKeyNames and Name set.

Просмотреть файл

@ -0,0 +1,3 @@
This example demonstrates how to persist the selected items in a hierarchical RadGrid.When all items on a particular level are selected the parent item should also be selected.
If one of the items on the level is not selected the parent item should not be selected as well.
In order for the algorithm to work correctly each GridTableView should have DataKeyNames and Name set.

1
TreeView/Readme.txt Normal file
Просмотреть файл

@ -0,0 +1 @@
Examples related to RadTreeView

14
TreeView/TreeView.sln Normal file
Просмотреть файл

@ -0,0 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{E4C5164C-9DF5-4D31-8BA0-9B0667418C44}"
ProjectSection(SolutionItems) = preProject
Readme.txt = Readme.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

Двоичные данные
TreeView/TreeView.zip Normal file

Двоичный файл не отображается.