or
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxExample.aspx.cs" Inherits="WolperWeb.company.AjaxExample" %>
<%@ 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
></
title
>
<
script
type
=
"text/javascript"
language
=
"javascript"
src
=
"../scripts/jquery-1.4.1.js"
></
script
>
<
telerik:RadCodeBlock
ID
=
"rcbJavaScript"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
$(function () {
////////////////////////////////////////////////////////////////////////////////////////////////////////
/// TEST CODE /////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
/// REQURIED PARAMETERS : int WebID, int AccountID, string SearchTerm, int CurrentPage, int PageSize
/////////////////////////////////////////////////////////////////////////////////////////////////////
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "ajaxexample.aspx/GetData",
data: "{ }",
success: function (result) {
var publications = (typeof result.d) == 'string' ? eval('(' + result.d + ')') : result.d;
for (var key in publications) {
if (key == "book") {
tableView.set_dataSource(publications[key]);
tableView.dataBind();
}
}
},
error: function (xhr, ajaxOptions) {
alert("error: " + xhr.responseText);
}
});
});
var tableView;
function pageLoad(sender, args) {
tableView = $find("<%= rgPublicationResults.ClientID %>").get_masterTableView();
}
function rgPublicationResults_Command(sender, args) { }
</
script
>
</
telerik:RadCodeBlock
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
telerik:RadGrid
ID
=
"rgPublicationResults"
runat
=
"server"
Skin
=
"Simple"
OnItemDataBound
=
"rgPublicationResults_ItemDataBound"
>
<
ClientSettings
AllowColumnsReorder
=
"true"
>
<
ClientEvents
OnCommand
=
"rgPublicationResults_Command"
/>
</
ClientSettings
>
<
MasterTableView
GridLines
=
"None"
AutoGenerateColumns
=
"false"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"BookName"
HeaderText
=
"Title"
UniqueName
=
"BookName"
/>
<
telerik:GridBoundColumn
DataField
=
"Term"
HeaderText
=
"Term"
UniqueName
=
"Author"
/>
<
telerik:GridBoundColumn
DataField
=
"BookID"
HeaderText
=
"ID"
UniqueName
=
"BookID"
/>
<
telerik:GridTemplateColumn
HeaderText
=
"Price"
UniqueName
=
"Price"
>
<
ItemTemplate
>
<%# GetPrice(Eval("Price")) %>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"TestField"
UniqueName
=
"TestField"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblTest"
runat
=
"server"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
<
AlternatingItemStyle
VerticalAlign
=
"Top"
/>
<
ItemStyle
VerticalAlign
=
"Top"
/>
</
MasterTableView
>
</
telerik:RadGrid
>
</
form
>
</
body
>
</
html
>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using Telerik.Web.UI;
namespace WolperWeb.company
{
public partial class AjaxExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected string GetPrice(object Price)
{
try
{
return String.Format("Order Total: {0:C}", Price);
}
catch { return "failed"; }
}
protected void rgPublicationResults_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item.ItemType == GridItemType.AlternatingItem || e.Item.ItemType == GridItemType.Item)
{
Label lblTest = (Label)e.Item.FindControl("lblTest");
lblTest.Text = "test";
}
}
[WebMethod]
public static Dictionary<
string
, object> GetData()
{
Dictionary<
string
, object> result = new Dictionary<
string
, object>();
List<
BookData
> lBooks = new List<
BookData
>();
BookData oBook = new BookData();
oBook.Author = "John Smith";
oBook.BookID = "bk101";
oBook.BookName = "Book Number 1";
oBook.Price = 10;
lBooks.Add(oBook);
oBook = new BookData();
oBook.Author = "Bill Smith";
oBook.BookID = "bk102";
oBook.BookName = "Book Number 2";
oBook.Price = 15;
lBooks.Add(oBook);
oBook = new BookData();
oBook.Author = "Rob Smith";
oBook.BookID = "bk103";
oBook.BookName = "Book Number 3";
oBook.Price = 20;
lBooks.Add(oBook);
oBook = new BookData();
oBook.Author = "Jane Smith";
oBook.BookID = "bk104";
oBook.BookName = "Book Number 4";
oBook.Price = 25;
lBooks.Add(oBook);
result.Add("book", lBooks);
return result;
}
}
public struct BookData
{
public string BookName { get; set; }
public string BookID { get; set; }
public string Author { get; set; }
public decimal Price { get; set; }
}
}
var tableView;
function pageLoad(sender, args) {
tableView = $find("<%= rgPublicationResults.ClientID %>").get_masterTableView();
}
GridEditableItem item = e.Item
as
GridEditableItem;
Hashtable values =
new
Hashtable();
DataTable dt =
new
DataTable();
item.ExtractValues(values);
Protected
Sub
UserNeedDatasource(sender
As
Object
, e
As
Telerik.Web.UI.GridNeedDataSourceEventArgs)
Dim
DataKey
As
String
=
Me
.Grid1.MasterTableView.DataKeyValues(
Me
.Grid1SelectedIndexes(0))(
"DataKeyName"
).ToString
Me
.Grid2.DataSource = MyDataSource.GetData(DataKey)
end
Sub
protected void RadGrid1_Load(object source, GridNeedDataSourceEventArgs e)
{
String ConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(ConnString);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = new SqlCommand(@"SELECT columns FROM tables)", conn);
DataSet myDataTable = new DataSet();
conn.Open();
try
{
adapter.Fill(myDataTable, "tables");
}
finally
{
conn.Close();
}
DataView myDataView = myDataTable.Tables["tabels"].DefaultView;
RadGrid1.MasterTableView.DataSource = myDataView;
RadGrid1.MasterTableView.DataBind();
}
<
telerik:RadAjaxPanel
ID
=
"RadAjaxPanel2"
runat
=
"server"
>
<
div
class
=
"EnterpriseNodes1"
>
<
telerik:RadComboBox
ID
=
"RadComboBox1"
runat
=
"server"
Skin
=
"WebBlue"
MarkFirstMatch
=
"true"
Visible
=
"false"
AllowCustomText
=
"true"
Filter
=
"StartsWith"
CssClass
=
"combo1"
NoWrap
=
"True"
OnItemDataBound
=
"RadComboBox1_ItemDataBound"
AutoPostBack
=
"false"
OnSelectedIndexChanged
=
"RadComboBox1_OnSelectedIndexChanged"
OnClientSelectedIndexChanged
=
"RadComboBox1_OnClientSelectedIndexChanged"
>
</
telerik:RadComboBox
>
<
br
/>
<
telerik:RadComboBox
ID
=
"RadComboBox2"
runat
=
"server"
Skin
=
"WebBlue"
MarkFirstMatch
=
"true"
Visible
=
"false"
AllowCustomText
=
"true"
Filter
=
"StartsWith"
CssClass
=
"combo2"
NoWrap
=
"True"
OnItemDataBound
=
"RadComboBox2_ItemDataBound"
AutoPostBack
=
"false"
OnSelectedIndexChanged
=
"RadComboBox2_OnSelectedIndexChanged"
OnClientSelectedIndexChanged
=
"RadComboBox2_OnClientSelectedIndexChanged"
>
</
telerik:RadComboBox
>
<
br
/>
</
div
>
</
telerik:RadAjaxPanel
>
function
RadComboBox1_OnClientSelectedIndexChanged(sender, args) {
__doPostBack(
'RadComboBox1'
,
''
);
}
function
RadComboBox2_OnClientSelectedIndexChanged(sender, args) {
__doPostBack(
'RadComboBox2'
,
''
);
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
RadComboBoxItem item =
null
;
item =
new
RadComboBoxItem();
item.Value =
"1"
;
item.Text =
"Canada"
;
RadComboBox1.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"2"
;
item.Text =
"USA"
;
RadComboBox1.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"3"
;
item.Text =
"BC"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"4"
;
item.Text =
"NB"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"5"
;
item.Text =
"ON"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"6"
;
item.Text =
"CAL"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"7"
;
item.Text =
"FLA"
;
RadComboBox2.Items.Add(item);
item =
new
RadComboBoxItem();
item.Value =
"8"
;
item.Text =
"NY"
;
RadComboBox2.Items.Add(item);
RadComboBox1.Text =
""
;
RadComboBox1.ClearSelection();
RadComboBox1.Visible =
true
;
RadComboBox2.Text =
""
;
RadComboBox2.ClearSelection();
RadComboBox2.Visible =
true
;
}
}
protected
void
RadComboBox1_OnSelectedIndexChanged(
object
sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
FilterNext(
ref
RadComboBox1,
ref
RadComboBox2);
}
private
void
FilterNext(
ref
RadComboBox cbCurrent,
ref
RadComboBox cbNext)
{
if
(cbCurrent.Text ==
"Canada"
)
{
for
(
int
i = 0; i <= cbNext.Items.Count - 1; i++)
{
if
(cbNext.Items[i].Text ==
"BC"
|| cbNext.Items[i].Text ==
"NB"
|| cbNext.Items[i].Text ==
"ON"
)
{
cbNext.Items[i].Visible =
true
;
//WriteLog("true " + cbNext.Items[i].Text);
}
else
{
cbNext.Items[i].Visible =
false
;
//WriteLog("false " + cbNext.Items[i].Text);
}
}
}
if
(cbCurrent.Text ==
"USA"
)
{
for
(
int
i = 0; i <= cbNext.Items.Count - 1; i++)
{
if
(cbNext.Items[i].Text ==
"CAL"
|| cbNext.Items[i].Text ==
"FLA"
|| cbNext.Items[i].Text ==
"NY"
)
{
cbNext.Items[i].Visible =
true
;
//WriteLog("true " + cbNext.Items[i].Text);
}
else
{
cbNext.Items[i].Visible =
false
;
//WriteLog("false " + cbNext.Items[i].Text);
}
}
}
cbNext.DataBind();
}