當(dāng)前位置:
首頁(yè) >
telerik学习总结
發(fā)布時(shí)間:2024/1/1
34
豆豆
生活随笔
收集整理的這篇文章主要介紹了
telerik学习总结
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
Telerik
Telerik 是保加利亞的一個(gè)軟件公司,專(zhuān)注于微軟.Net平臺(tái)的表示層與內(nèi)容管理控件。Telerik 提供高度穩(wěn)定性和豐富性能的組件產(chǎn)品,并可應(yīng)用在非常嚴(yán)格的環(huán)境中。現(xiàn)在 擁有 Microsoft, HP, Alcoa, BP, Harper Collins,?
Siemens, T-Mobile, HJ Heinz和一些最主要的教育機(jī)構(gòu)和很多政府機(jī)關(guān)等客戶。
? ? ? ?telerik 的 r.a.d.controls 套裝是一款最具革命性和廣泛性的開(kāi)發(fā)工具集,它主要針對(duì)專(zhuān)業(yè)級(jí)的 ASP.NET?
開(kāi)發(fā),適用于 AJAX, Atlas 、Visual Studio .NET 2005 、Visual Studio 2008 及 ASP.NET 3.5。通過(guò)該產(chǎn)品的
強(qiáng)大功能,開(kāi)發(fā)者可以開(kāi)發(fā)出功能豐富、適應(yīng)標(biāo)準(zhǔn)廣泛,與交互瀏覽器兼容的網(wǎng)絡(luò)應(yīng)用程序。
? ? ? ?2012年,Telerik新推出了Icenium服務(wù),該服務(wù)是一個(gè)集成的云環(huán)境(Integrated Cloud Enviroment,ICE
)。
? ? ? ?數(shù)十年來(lái),IDE一直是應(yīng)用開(kāi)發(fā)的基礎(chǔ),微軟Visual Studio,Eclipse、NetBeans等都是IDE的代表。IDE的
問(wèn)題是開(kāi)發(fā)和部署有許多繁瑣的要求,在環(huán)境和客戶端種類(lèi)繁多的移動(dòng)時(shí)代已經(jīng)顯得支撐不足。
? ? ? ?針對(duì)IDE的這些弊端,Icenium把所有移動(dòng)應(yīng)用開(kāi)發(fā)都搬到了云上面,把IDE中的SDK、編譯器、測(cè)試、調(diào)試、
數(shù)字認(rèn)證等,通通都變成了云服務(wù),這樣的話開(kāi)發(fā)者就可以在任何設(shè)備、任何開(kāi)發(fā)環(huán)境上開(kāi)發(fā)應(yīng)用,從而擺脫物理
環(huán)境或特定平臺(tái)的束縛。
? ? ? ?Icenium具有一次開(kāi)發(fā)、支持多種部署的能力。該服務(wù)可通過(guò)瀏覽器訪問(wèn),用戶可運(yùn)用其HTML5、CSS及
JavaScript技能來(lái)創(chuàng)建部署應(yīng)用,所創(chuàng)建的原生應(yīng)用可以在蘋(píng)果iOS平臺(tái)和Google Android平臺(tái)運(yùn)行。
? ? ? ?在Icenium中,開(kāi)發(fā)者可利用Apache Cordova開(kāi)發(fā)具備拍照、加速計(jì)、定位等功能的混合型應(yīng)用。可訪問(wèn)
GitHub等給予URL的Git容器。集成的版本控制允許保存代碼,并在云端進(jìn)行版本化,從而可以在任何時(shí)間任何地方
訪問(wèn)這些代碼。
? ? ? ?cenium還有一個(gè)集成的模擬環(huán)境,讓開(kāi)發(fā)者無(wú)需部署就可以看到應(yīng)用在設(shè)備端的樣子。Icenium還允許開(kāi)發(fā)
者了解應(yīng)用在不同外形因素下的樣子。開(kāi)發(fā)者可以在數(shù)分鐘之內(nèi)實(shí)現(xiàn)傳統(tǒng)方法需要半小時(shí)或更多的時(shí)間才能完成的
事情。
? ? ? ?與Icenium類(lèi)似的服務(wù)還有PhoneGap和Kii Cloud。這些服務(wù)降低了開(kāi)發(fā)復(fù)雜性,加快了開(kāi)發(fā)速度,對(duì)IDE缺
乏深入了解的開(kāi)發(fā)者以及希望加速應(yīng)用部署及有效管理開(kāi)發(fā)的企業(yè)來(lái)說(shuō)都具有很大的吸引力。
? ? ? ?Icenium于去年夏天開(kāi)始進(jìn)行不公開(kāi)beta測(cè)試,現(xiàn)在已經(jīng)開(kāi)放公測(cè)至明年5月份,有興趣的同學(xué)不妨到其網(wǎng)站
試試。
========
Telerik控件使用
方法/步驟
1
RadGrid添加序號(hào)列
<telerik:GridTemplateColumn HeaderText="序號(hào)列">
? ? ? ? ? ? ? ? ? ? <ItemTemplate> ? ? ? ? ? ? ? ? ? ? ? ?<%#System.Convert.ToInt32(DataBinder.Eval
(Container,"ItemIndex"))+1 %>
? ? ? ? ? ? ? ? ? ? </ItemTemplate>
?</telerik:GridTemplateColumn>
2
telerik:RadWindow 彈出窗口
<telerik:RadWindowManager>→<Windows>→<telerik:RadWindow>→ <ContentTemplate>?
? ? a.AutoSize:自適應(yīng)大小
? ? b.ReloadOnShow:
? ? c.ShowContentDuringLoad:
? ? d.VisibleOnPageLoad:load時(shí)顯示窗口
? ? e.Modal:
? ? f.Behaviors:彈出窗口都有哪些操作例如大小化、關(guān)閉等
? ? g.Title:
? ? h.VisibleStatusbar:隱藏狀態(tài)條
例:
3
RadDateTimePicker日期控件
<telerik:RadDateTimePicker ID="RadDateBirthday" runat="server" ? MinDate="2009-01-09"?
ShowPopupOnFocus="true">
? ? ? ? <DateInput BorderColor="Blue" DateFormat="yyyy-MM-dd">
? ? ? ? </DateInput>
? ? ? ? <Calendar runat="server" ID="calendar">
? ? ? ? </Calendar>
? ? ? ? <DatePopupButton runat="server" Visible="true" />
?</telerik:RadDateTimePicker>
a.ShowPopupOnFocus="true" 點(diǎn)擊文本框時(shí)顯示時(shí)間panel
b.DateFormat 格式化時(shí)間
========
一個(gè)Asp.net MVC 控件項(xiàng)目分析---Telerik.Web.Mvc
? ? ? 在寫(xiě)本文之前,本人一直抱著‘不宜’在asp.net MVC框架下搞什么控件開(kāi)發(fā)的想法,因?yàn)橐惶岬娇丶蜁?huì)讓人想起‘事件’,‘VIEWSTATE’等一些問(wèn)題,而asp.net MVC下是Controller, Action, Viewpage, Filter等特性
的‘天下’。所以總感覺(jué)‘驢唇對(duì)不上馬嘴’。
? ? ? 但直到前陣子在郵箱中收到了關(guān)于telerik關(guān)于MVC框架擴(kuò)展的一些信息之后,才發(fā)現(xiàn)這家商業(yè)控件公司也開(kāi)
始打MVC的主意了。而這個(gè)項(xiàng)目(開(kāi)源)就是該公司在理解了asp.net mvc的基礎(chǔ)上所做的一些嘗試,當(dāng)然其所實(shí)現(xiàn)
的所謂控件與之前我們?cè)陧?xiàng)目中所開(kāi)發(fā)或使用的web服務(wù)器控件有很大的不同,可以說(shuō)是拋棄了以往的設(shè)計(jì)方式。盡
管目前它的這種做法我心里還打著問(wèn)號(hào),但必定是一種嘗試(不管你贊同還是不贊同)。下面就做一個(gè)簡(jiǎn)單的分析
,希望能給研究MVC架構(gòu)的朋友提供一些的思考。
? ? ? 首先要聲明的是該開(kāi)源項(xiàng)目中所使用的js就是jquery,而那些顯示效果也基本上就是基于jquery中的那件插
件為原型,并進(jìn)行相應(yīng)的屬性封裝,以便于在viewpage中用c#等語(yǔ)言進(jìn)行聲明綁定。下面就其中一些控件的顯示截
圖:
? ? ? telerik_mvc_accordion
? ? ?telerik_mvc_date
? ? ?telerik_mvc_slider
? ? ? telerik_mvc_progressbar
? ? ? ?在該開(kāi)源項(xiàng)目中,所有控件均基于jQueryViewComponentBase (abstract 類(lèi)型),但其自身屬性并不多,而
所有的控件基類(lèi)屬性都被jQueryViewComponentBase 的父類(lèi)ViewComponentBase所定義,下面以控件中
的“Accordion(屬性頁(yè)控件)”為例進(jìn)行說(shuō)明,見(jiàn)下圖:
telerik_mvc_baseclass
? ? ? 上圖中左側(cè)的就是ViewComponentBase類(lèi),其定義了多數(shù)控件屬性,比如js腳本名稱(chēng)和路徑以及相關(guān)樣式以及
最終的html元素輸出方法,因?yàn)槠漕?lèi)也是抽象類(lèi),所以其中大部分方法均為定義,而未進(jìn)行具體實(shí)現(xiàn)。我們只要關(guān)
注一下其構(gòu)造方法就可以了:
? /// <summary>
? ? /// View component base class.
? ? /// </summary>
? ? public abstract class ViewComponentBase : IStyleableComponent, IScriptableComponent
? ? {
? ? ? ? private string name;
? ? ? ? private string styleSheetFilesLocation;
? ? ? ? private string scriptFilesLocation;
? ? ? ? /// <summary>
? ? ? ? /// 初始化相關(guān)Initializes a new instance of the <see cref="ViewComponentBase"/> class.
? ? ? ? /// </summary>
? ? ? ? /// <param name="viewContext">當(dāng)前視圖的上下文,將會(huì)在子類(lèi)中使用</param>
? ? ? ? /// <param name="clientSideObjectWriterFactory">傳入當(dāng)前所使用的Writer工廠實(shí)例.通過(guò)子類(lèi)注入,
子類(lèi)最終延伸到相對(duì)應(yīng)的控件實(shí)例</param>
? ? ? ? protected ViewComponentBase(ViewContext viewContext, IClientSideObjectWriterFactory?
clientSideObjectWriterFactory)
? ? ? ? {
? ? ? ? ? ? Guard.IsNotNull(viewContext, "viewContext");
? ? ? ? ? ? Guard.IsNotNull(clientSideObjectWriterFactory, "clientSideObjectWriterFactory");
? ? ? ? ? ? ViewContext = viewContext;
? ? ? ? ? ? ClientSideObjectWriterFactory = clientSideObjectWriterFactory;
? ? ? ? ? ? StyleSheetFilesPath = WebAssetDefaultSettings.StyleSheetFilesPath;
? ? ? ? ? ? StyleSheetFileNames = new List<string>();
? ? ? ? ? ? ScriptFilesPath = WebAssetDefaultSettings.ScriptFilesPath;
? ? ? ? ? ? ScriptFileNames = new List<string>();
? ? ? ? ? ? HtmlAttributes = new RouteValueDictionary();
? ? ? ? }?
? ? 通過(guò)上述的構(gòu)造方法,就可以將控件的一些通用默認(rèn)屬性值進(jìn)行初始化了。
? ? 下面以“Accordion”的源碼來(lái)分析一下,這里還是從構(gòu)造方法入手:?
public class Accordion : jQueryViewComponentBase, IAccordionItemContainer
? ?{
? ? ? ?……
? ? ? ?/// <summary>
? ? ? ?/// Initializes a new instance of the <see cref="Accordion"/> class.
? ? ? ?/// </summary>
? ? ? ?/// <param name="viewContext">The view context.</param>
? ? ? ?/// <param name="clientSideObjectWriterFactory">The client side object writer factory.</param>
? ? ? ?public Accordion(ViewContext viewContext, IClientSideObjectWriterFactory?
clientSideObjectWriterFactory) : base(viewContext, clientSideObjectWriterFactory)
? ? ? ?{
? ? ? ? ? ?Items = new List<AccordionItem>();
? ? ? ? ? ?autoHeight = true;
? ? ? ?}?
? ? ? 注:上面的構(gòu)程方法后面加入了base(viewContext, clientSideObjectWriterFactory),以實(shí)現(xiàn)向基類(lèi)構(gòu)造
方法傳參,也就是實(shí)現(xiàn)了上面所說(shuō)的將當(dāng)前控件所使用的viewContext,clientSideObjectWriterFactory傳遞到基
類(lèi)ViewComponentBase 中去。(注:最終的clientSideObjectWriterFactory為ClientSideObjectWriterFactory實(shí)
例類(lèi)型)。
? ? ? 當(dāng)然,因?yàn)樵摽丶闹邢鄳?yīng)屬性比較簡(jiǎn)單,只是一些set,get語(yǔ)法,所以就不過(guò)多介紹了,相信做過(guò)控件開(kāi)發(fā)
的對(duì)這些再熟悉不過(guò)了。
? ? ? 下面主要介紹一下其write html元素時(shí)所使用的方法,如下:
?/// <summary>
? ? ? /// 創(chuàng)建并寫(xiě)入初始化腳本對(duì)象和相應(yīng)屬性.
? ? ? /// </summary>
? ? ? /// <param name="writer">The writer.</param>
? ? ? public override void WriteInitializationScript(TextWriter writer)
? ? ? {
? ? ? ? ? int selectedIndex = Items.IndexOf(GetSelectedItem());
? ? ? ? ? IClientSideObjectWriter objectWriter = ClientSideObjectWriterFactory.Create(Id,?
"accordion", writer);
? ? ? ? ? objectWriter.Start()
? ? ? ? ? ? ? ? ? ? ? .Append("active", selectedIndex, 0)
? ? ? ? ? ? ? ? ? ? ? .Append("animated", AnimationName)
? ? ? ? ? ? ? ? ? ? ? .Append("autoHeight", AutoHeight, true)
? ? ? ? ? ? ? ? ? ? ? .Append("clearStyle", ClearStyle, false)
? ? ? ? ? ? ? ? ? ? ? .Append("collapsible", CollapsibleContent, false)
? ? ? ? ? ? ? ? ? ? ? .Append("event", OpenOn)
? ? ? ? ? ? ? ? ? ? ? .Append("fillSpace", FillSpace, false);
? ? ? ? ? if (!string.IsNullOrEmpty(Icon) || !string.IsNullOrEmpty(SelectedIcon))
? ? ? ? ? {
? ? ? ? ? ? ? if (!string.IsNullOrEmpty(Icon) && !string.IsNullOrEmpty(SelectedIcon))
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? objectWriter.Append("icons:{'header':'" + Icon + "','headerSelected':'" +?
SelectedIcon + "'}");
? ? ? ? ? ? ? }
? ? ? ? ? ? ? else if (!string.IsNullOrEmpty(Icon))
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? objectWriter.Append("icons:{'header':'" + Icon + "'}");
? ? ? ? ? ? ? }
? ? ? ? ? ? ? else if (!string.IsNullOrEmpty(SelectedIcon))
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? objectWriter.Append("icons:{'headerSelected':'" + SelectedIcon + "'}");
? ? ? ? ? ? ? }
? ? ? ? ? }
? ? ? ? ? objectWriter.Append("change", OnChange).Complete();
? ? ? ? ? base.WriteInitializationScript(writer);
? ? ? }?
? ? ? 可以看出,objectWriter (IClientSideObjectWriter 類(lèi)型實(shí)例)中被綁定了相關(guān)的控件屬性,并通過(guò)其類(lèi)
的WriteInitializationScript(writer)進(jìn)行腳本的輸出。而基本類(lèi)的相應(yīng)方法如下: ? ?
? ?/// <summary>
? ? ? /// Writes the initialization script.
? ? ? /// </summary>
? ? ? /// <param name="writer">The writer.</param>
? ? ? public virtual void WriteInitializationScript(TextWriter writer)
? ? ? {
? ? ? }?
? ? ? 大家看到該方法為空,但其又是如何運(yùn)行起來(lái)的呢,這里先賣(mài)個(gè)關(guān)子,稍后再說(shuō)。接著再看一下另一個(gè)方法
:WriteHtml()
? /// <summary>
? ? ? /// 輸出當(dāng)前的 HTML代碼.
? ? ? /// </summary>
? ? ? protected override void WriteHtml()
? ? ? {
? ? ? ? ? AccordionItem selectedItem = GetSelectedItem();
? ? ? ? ? TextWriter writer = ViewContext.HttpContext.Response.Output;
? ? ? ? ? if (!string.IsNullOrEmpty(Theme))
? ? ? ? ? {
? ? ? ? ? ? ? writer.Write("<div class=\"{0}\">".FormatWith(Theme));
? ? ? ? ? }
? ? ? ? ? HtmlAttributes.Merge("id", Id, false);
? ? ? ? ? HtmlAttributes.AppendInValue("class", " ", "ui-accordion ui-widget ui-helper-reset");
? ? ? ? ? writer.Write("<div{0}>".FormatWith(HtmlAttributes.ToAttributeString()));
? ? ? ? ? foreach (AccordionItem item in Items)
? ? ? ? ? {
? ? ? ? ? ? ? item.HtmlAttributes.AppendInValue("class", " ", "ui-accordion-header ui-helper-reset?
ui-state-default ");
? ? ? ? ? ? ? item.ContentHtmlAttributes.AppendInValue("class", " ", "ui-accordion-content ui-
helper-reset ui-widget-content ui-corner-bottom");
? ? ? ? ? ? ? if (item == selectedItem)
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? item.ContentHtmlAttributes.AppendInValue("class", " ", "ui-accordion-content-
active");
? ? ? ? ? ? ? }
? ? ? ? ? ? ? else
? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? item.HtmlAttributes.AppendInValue("class", " ", "ui-corner-all");
? ? ? ? ? ? ? }
? ? ? ? ? ? ? writer.Write("<h3{0}><a href=\"#\">{1}</a></h3>".FormatWith
(item.HtmlAttributes.ToAttributeString(), item.Text));
? ? ? ? ? ? ? item.ContentHtmlAttributes.AppendInValue("style", ";", (item == selectedItem) ??
"display:block" : "display:none");
? ? ? ? ? ? ? writer.Write("<div{0}>".FormatWith(item.ContentHtmlAttributes.ToAttributeString()));
? ? ? ? ? ? ? item.Content();
? ? ? ? ? ? ? writer.Write("</div>");
? ? ? ? ? }
? ? ? ? ? writer.Write("</div>");
? ? ? ? ? if (!string.IsNullOrEmpty(Theme))
? ? ? ? ? {
? ? ? ? ? ? ? writer.Write("</div>");
? ? ? ? ? }
? ? ? ? ? base.WriteHtml();
? ? ? }?
? ? ? 該方法首先獲取當(dāng)前所選屬性頁(yè)標(biāo)簽(GetSelectedItem()方法),然后用foreach方法對(duì)屬性頁(yè)標(biāo)簽集合進(jìn)
行遍歷,并判斷當(dāng)前屬性頁(yè)是否就是被選中的屬性頁(yè),并綁定上相應(yīng)的css屬性。其最終也是調(diào)用相應(yīng)的基類(lèi)方法進(jìn)
行輸出。當(dāng)然這里基類(lèi)方法也是為空,呵呵。
? ? ?準(zhǔn)備好了這個(gè)控件類(lèi)之后,Telerik還為Accordion控件‘準(zhǔn)備’了一些輔助組件,比如屬性頁(yè)組件
(AccordionItem),以及相關(guān)的組件構(gòu)造器(AccordionItemBuilder,AccordionBuilder),這樣我們就可以通過(guò)
這些構(gòu)造器很方便的創(chuàng)建相應(yīng)的控件和組件了,下面就以AccordionItemBuilder為例,解釋一下其構(gòu)造器結(jié)構(gòu):
public class AccordionBuilder : ViewComponentBuilderBase<Accordion, AccordionBuilder>,?
IHideObjectMembers
? ?{
? ? ? /// <summary>
? ? ? /// 初始化方法Initializes a new instance of the <see cref="AccordionBuilder"/> class.
? ? ? /// </summary>
? ? ? /// <param name="component">The component.</param>
? ? ? public AccordionBuilder(Accordion component) : base(component)
? ? ? {}
? ? ? /// <summary>
? ? ? /// 指定一個(gè)屬性頁(yè)選項(xiàng)
? ? ? /// </summary>
? ? ? /// <param name="addAction">要添加的action.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder Items(Action<AccordionItemFactory> addAction)
? ? ? {
? ? ? ? ? Guard.IsNotNull(addAction, "addAction");
? ? ? ? ? AccordionItemFactory factory = new AccordionItemFactory(Component);
? ? ? ? ? addAction(factory);
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 屬性頁(yè)動(dòng)態(tài)效果顯示名稱(chēng)(鼠標(biāo)在屬性頁(yè)移入移出時(shí))
? ? ? /// </summary>
? ? ? /// <param name="effectName">Name of the effect.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder Animate(string effectName)
? ? ? {
? ? ? ? ? Component.AnimationName = effectName;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 是否高度自適用.
? ? ? /// </summary>
? ? ? /// <param name="value">if set to <c>true</c> value.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder AutoHeight(bool value)
? ? ? {
? ? ? ? ? Component.AutoHeight = value;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 指定要觸發(fā)的屬性頁(yè)事件名稱(chēng).
? ? ? /// </summary>
? ? ? /// <param name="eventName">Name of the event.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder OpenOn(string eventName)
? ? ? {
? ? ? ? ? Component.OpenOn = eventName;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 所使用的Icons名稱(chēng).
? ? ? /// </summary>
? ? ? /// <param name="name">The name.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder Icon(string name)
? ? ? {
? ? ? ? ? Component.Icon = name;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 被選中的屬性頁(yè)所使用的Icons 名稱(chēng)
? ? ? /// </summary>
? ? ? /// <param name="name">The name.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder SelectedIcon(string name)
? ? ? {
? ? ? ? ? Component.SelectedIcon = name;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 當(dāng)屬性頁(yè)發(fā)生變化時(shí)要傳遞的action 腳本.
? ? ? /// </summary>
? ? ? /// <param name="javaScript">The java script.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder OnChange(Action javaScript)
? ? ? {
? ? ? ? ? Component.OnChange = javaScript;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// Specify the name of the theme applies to the accordion.
? ? ? /// </summary>
? ? ? /// <param name="name">The name.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder Theme(string name)
? ? ? {
? ? ? ? ? Component.Theme = name;
? ? ? ? ? return this;
? ? ? }
? }?
?
? ? ?對(duì)于上面的OnChange方法,可以使用下面的方法將相應(yīng)的js腳本傳入并執(zhí)行
.OnChange(() =>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {%>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? function(event, ui)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $('#trace').append('Change fired: ' + new Date() +?
'<br/>');
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <%}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? )?
? ? 這樣,當(dāng)屬性頁(yè)發(fā)生變化時(shí),就會(huì)在頁(yè)面的指定區(qū)域?qū)⒆兓瘯r(shí)間顯示出來(lái)了,如下圖:
? ?telerik_mvc_onchange
??
? ? Telerik在jQueryViewComponentFactory中對(duì)項(xiàng)目中每一個(gè)控件提供了一個(gè)方法用以初始化相應(yīng)的構(gòu)造器,以便
于創(chuàng)建相應(yīng)的控件,比如Accordion,形如: ?
? ?/// <summary>
? ? ?/// Creates a accordion for ASP.NET MVC view.
? ? ?/// </summary>
? ? ?/// <returns></returns>
? ? ?[DebuggerStepThrough]
? ? ?public virtual AccordionBuilder Accordion()
? ? ?{
? ? ? ? ?return new AccordionBuilder(Create(() => new Accordion(ViewContext,?
clientSideObjectWriterFactory)));
? ? ?}?
? ? 而對(duì)于其在VIEW中的使用,則通過(guò)擴(kuò)展方法來(lái)加以聲明:
public static class HtmlHelperExtension
? ?{
? ? ? ?private static readonly IClientSideObjectWriterFactory factory = new?
ClientSideObjectWriterFactory();
? ? ? ?/// <summary>
? ? ? ?/// Gets the jQuery view components instance.
? ? ? ?/// </summary>
? ? ? ?/// <param name="helper">The html helper.</param>
? ? ? ?/// <returns>jQueryViewComponentFactory</returns>
? ? ? ?[DebuggerStepThrough]
? ? ? ?public static jQueryViewComponentFactory jQuery(this HtmlHelper helper)
? ? ? ?{
? ? ? ? ? ?return new jQueryViewComponentFactory(helper, factory);
? ? ? ?}
? ?}?
? ? 這樣在頁(yè)面視圖中,我們這可以使用下面的寫(xiě)法來(lái)構(gòu)造一個(gè)Accordion控件了:
<% Html.jQuery().Accordion()
? ? ? ? ? ? ? ? ? .Name("myAccordion")
? ? ? ? ? ? ? ? ? .Animate("bounceslide")
? ? ? ? ? ? ? ? ? .Items(parent =>
? ……?
?
? ? ?上面只是介紹了前臺(tái)和底層代碼如果顯示的問(wèn)題,但還沒(méi)有解釋之前所說(shuō)的WriteInitializationScript
(TextWriter writer)方法以及WriteHtml()
方法如何被調(diào)用的問(wèn)題,正如之前所看到的,因?yàn)锳ccordion的基類(lèi)ViewComponentBase中未實(shí)現(xiàn)具體的代碼,所以
這里我們要將注意力轉(zhuǎn)移到 jQueryViewComponentFactory中,請(qǐng)看如下代碼:?
private TViewComponent Create<TViewComponent>(Func<TViewComponent> factory) where TViewComponent :?
ViewComponentBase
? ? ? ?{
? ? ? ? ? ?TViewComponent component = factory();
? ? ? ? ? ?if (component is jQueryViewComponentBase)
? ? ? ? ? ?{
? ? ? ? ? ? ? ?component.AssetKey = DefaultAssetKey;
? ? ? ? ? ?}
? ? ? ? ? ?htmlHelper.Telerik().StyleSheetRegistrar().ToRegistrar().Register(component);
? ? ? ? ? ?htmlHelper.Telerik().ScriptRegistrar().ToRegistrar().Register(component);
? ? ? ? ? ?return component;
? ? ? ?}?
? ? ?上面的方法其實(shí)就是之前在該類(lèi)方法Accordion()中所調(diào)用并執(zhí)行的:
? ? ?return new AccordionBuilder(Create(() => new Accordion(ViewContext,?
clientSideObjectWriterFactory)));
? ? ?通過(guò)該方法,就可以將該控件及其相關(guān)組件信息注冊(cè)到相應(yīng)的視圖中。因?yàn)槲覀儽容^關(guān)注WriteHtml()方法,
所以這里就直接分析一下這一行代碼: ? ?
? ? ?ScriptRegistrar().ToRegistrar().Register(component);?
? ? ?ScriptRegistrar類(lèi)中的Register方法承擔(dān)著將當(dāng)前要?jiǎng)?chuàng)建的組件添加到當(dāng)前的腳本組件列表中的任務(wù)
(scriptableComponents為list列表) ? ??
? ? ? ?/// <summary>
? ? ? ?/// Registers the scriptable component.
? ? ? ?/// </summary>
? ? ? ?/// <param name="component">The component.</param>
? ? ? ?public virtual void Register(IScriptableComponent component)
? ? ? ?{
? ? ? ? ? ?Guard.IsNotNull(component, "component");
? ? ? ? ? ?if (!scriptableComponents.Contains(component))
? ? ? ? ? ?{
? ? ? ? ? ? ? ?scriptableComponents.Add(component);
? ? ? ? ? ?}
? ? ? ?}?
? ? ? 當(dāng)組件被成功添加到該list列表中后,系統(tǒng)就會(huì)調(diào)用Render()方法將其顯示出來(lái)(注:該方法與以前web控件
開(kāi)發(fā)中的顯示方法同名,所以比較好理解),如下: ? ?
? ? ? /// <summary>
? ? ? /// Writes the scripts in the response.
? ? ? /// </summary>
? ? ? public void Render()
? ? ? {
? ? ? ? ? if (hasRendered)
? ? ? ? ? {
? ? ? ? ? ? ? throw new InvalidOperationException
(Resources.TextResource.YouCannotCallRenderMoreThanOnce);
? ? ? ? ? }
? ? ? ? ? if (ViewContext.HttpContext.Request.Browser.EcmaScriptVersion.Major >= 1)
? ? ? ? ? {
? ? ? ? ? ? ? Write(ViewContext.HttpContext.Response.Output);
? ? ? ? ? }
? ? ? ? ? hasRendered = true;
? ? ? }?
? ? ?注意上面的這一行代碼:
? ?Write(ViewContext.HttpContext.Response.Output);
?
? ? ? 其所實(shí)現(xiàn)的功能如下: ??
? ? ? /// <summary>
? ? ? /// 寫(xiě)出所有腳本資源和腳本 statements.
? ? ? /// </summary>
? ? ? /// <param name="writer">The writer.</param>
? ? ? protected virtual void Write(TextWriter writer)
? ? ? {
? ? ? ? ? WriteScriptSources(writer);
? ? ? ? ? WriteScriptStatements(writer);
? ? ? }?
? ? ? ?而就是WriteScriptStatements這行代碼開(kāi)始執(zhí)行之前所說(shuō)的那個(gè)WriteInitializationScript(TextWriter?
writer)。而WriteHtml()方法的執(zhí)行入口要更加復(fù)雜一些,因?yàn)門(mén)elerik提供了ViewComponentBuilderBase這個(gè)類(lèi)來(lái)
進(jìn)行視圖組件的構(gòu)造,而該類(lèi)中的Render方法就是對(duì)相應(yīng)組件的Render方法(組件中已定義)進(jìn)行調(diào)用,如下:
? ? /// <summary>
? ? /// Renders the component.
? ? /// </summary>
? ? public virtual void Render()
? ? {
? ? ? ? Component.Render();
? ? }?
? ? ? 而之前的“Accordion”控件是繼承自ViewComponentBase類(lèi),所以相應(yīng)組件的Render方法就在該類(lèi)中進(jìn)行了
聲明定義,如下:
? ? ?/// <summary>
? ? ?/// Renders the component.
? ? ?/// </summary>
? ? ?public void Render()
? ? ?{
? ? ? ? ?EnsureRequired();
? ? ? ? ?WriteHtml();
? ? ?}?
? ? ? 大家看到了第二行代碼了吧,這就是我們之前看到的那個(gè)方法,也就是Accordion組件中WriteHtml()重寫(xiě)方
法的調(diào)用入口。
? ? ? 繞了這么一大圈,才把這個(gè)流程理清,是不是有些暈了。的確,剛開(kāi)始接觸時(shí)我也有點(diǎn)暈,但暈呀暈呀就‘
暈過(guò)去了’,現(xiàn)在再回頭看起來(lái)感常見(jiàn)其整體的架構(gòu)思路還是很清晰的。可以說(shuō)有了這瓶酒墊底,再分析該項(xiàng)目中
的其它控件就‘如魚(yú)得水’了。
? ? ? 最后不妨總結(jié)一下:
? ? ? 該項(xiàng)目中對(duì)asp.net mvc控件下的開(kāi)發(fā)做了一次嘗試,但如果之前做過(guò)控件特別是web服務(wù)器端控件開(kāi)發(fā)的朋
友,可以看出項(xiàng)目中有非常重的web控件開(kāi)發(fā)味道,基本連方法名稱(chēng)都有一定的重疊。
? ? ? 另外就是其自身還是引用了組件對(duì)象模型的概念,就拿屬性頁(yè)控件來(lái)說(shuō),就將其分為Accordion和
AccordionItem兩種類(lèi)型,其中可以將Accordion看成是AccordionItem的集合封裝(包括遍歷操作),而這里
AccordionItem就成了Accordion的一個(gè)組件,而Accordion又是當(dāng)前view中的一個(gè)組件。而組件開(kāi)發(fā)一直是.net平臺(tái)
上所倡導(dǎo)的。其優(yōu)勢(shì)在于可復(fù)用,維護(hù)方便,簡(jiǎn)化復(fù)雜問(wèn)題等。
? ? ? 好了,今天的內(nèi)容就先到這里了。
http://www.cnblogs.com/daizhj/archive/2009/09/09/1562966.html
========
Telerik RadGrid - DataSet (增刪查改)
Telerik RadGrid 數(shù)據(jù)展現(xiàn)、修改、刪除、增加, 數(shù)據(jù)源使用后臺(tái)DataSet綁定.
RadGrid支持彈出編輯形式。 條件是需要設(shè)置EditMode屬性彈出。 EditMode="PopUp"
<telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None"
? ? ? ? AllowPaging="True" PageSize="10" AllowSorting="True" AutoGenerateColumns="false"
? ? ? ? ShowStatusBar="true" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
? ? ? ? AllowAutomaticUpdates="True" HorizontalAlign="NotSet"?
onupdatecommand="RadGrid1_UpdateCommand"?
? ? ? ? onneeddatasource="RadGrid1_NeedDataSource" ondeletecommand="RadGrid1_DeleteCommand"?
oninsertcommand="RadGrid1_InsertCommand">
? ? ? ? <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="MenuID" EditMode="PopUp">
? ? <CommandItemSettings ExportToPdfText="Export to Pdf" AddNewRecordText="添加新項(xiàng)"?
? ? ? ? ? ? ? ? RefreshText="更新"></CommandItemSettings>
? ? ? ? ? ? <Columns>
? ? ? ? ? ? ? ? <telerik:GridEditCommandColumn EditText="修改">
? ? ? ? ? ? ? ? </telerik:GridEditCommandColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="MenuID" HeaderText="菜單序號(hào)"?
DataField="MenuID">
? ? ? ? ? ? ? ? ? ? <HeaderStyle Width="60px"></HeaderStyle>
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="SortNo" HeaderText="排序序號(hào)"?
DataField="SortNo">
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="ParentID" HeaderText="父節(jié)點(diǎn)"?
DataField="ParentID">
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="Name" HeaderText="名稱(chēng)" DataField="Name">
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="IconUrl" HeaderText="圖標(biāo)路徑"?
DataField="IconUrl">
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="Url" HeaderText="鏈接路徑" DataField="Url">
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridButtonColumn CommandName="Delete" Text="刪除" ConfirmText="確定刪除嗎?"?
UniqueName="column">
? ? ? ? ? ? ? ? </telerik:GridButtonColumn>
? ? ? ? ? ? </Columns>
? ? ? ? ? ? <EditFormSettings InsertCaption="添加新數(shù)據(jù)" CaptionFormatString="修改 菜單序號(hào): {0}"
? ? ? ? ? ? ? ? CaptionDataField="MenuID" EditFormType="Template"?
? ? ? ? ? ? ? ? PopUpSettings-Modal="true">
? ? ? ? ? ? ? ? <EditColumn UniqueName="EditCommandColumn1" EditText="修改"></EditColumn>
? ? ? ? ? ? ? ? <FormTemplate>
? ? ? ? ? ? ? ? ? ? <table id="Table1" cellspacing="1" cellpadding="1" width="250" border="0">
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 排序序號(hào):
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:TextBox ID="txtSortNo" Text='<%# Bind( "SortNo") %>'?
runat="server">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:TextBox>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 父節(jié)點(diǎn):
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:TextBox ID="txtParentID" Text='<%# Bind( "ParentID") %>'?
runat="server">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:TextBox>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 名稱(chēng):
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:TextBox ID="txtName" Text='<%# Bind( "Name") %>' runat="server">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:TextBox>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td colspan="2">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <hr />
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 是否啟用:
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:CheckBox ID="ckEnable" runat="server" Checked='<%# (Container is?
GridEditFormInsertItem) ? false : Eval("IsEnable") %>'/>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 圖標(biāo)路徑:
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:TextBox ID="txtIconUrl" runat="server" Text='<%# Bind( "IconUrl"?
) %>'>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:TextBox>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 鏈接路徑:
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:TextBox ID="txtUrl" runat="server" Text='<%# Bind( "Url") %>'>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:TextBox>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? </table>
? ? ? ? ? ? ? ? ? ? <table style="width: 100%">
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td align="right" colspan="2">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:Button ID="Button1" Text='<%# (Container is?
GridEditFormInsertItem) ? "插入" : "更新" %>'
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? runat="server" CommandName='<%# (Container is?
GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:Button>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:Button ID="Button2" Text="取消" runat="server"?
CausesValidation="False" CommandName="Cancel">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:Button>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? </table>
? ? ? ? ? ? ? ? </FormTemplate>
? ? ? ? ? ? </EditFormSettings>
? ? ? ? ? ? <PagerStyle FirstPageToolTip="首頁(yè)" LastPageToolTip="尾頁(yè)" NextPagesToolTip="下一頁(yè)"?
? ? ? ? ? ? ? ? NextPageToolTip="下一頁(yè)"
? ? ? ? ? ? ? ? PageSizeLabelText="頁(yè)數(shù):" PrevPagesToolTip="上一頁(yè)" PrevPageToolTip="上一頁(yè)" />
? ? ? ? </MasterTableView>
? ? </telerik:RadGrid>
ShowStatusBar="true" ?//顯示工具欄
EditFormType="Template" ?//所有類(lèi)型的編輯形式彈出可以顯示在編輯類(lèi)型AutoGenerated、WebUserControl和
Template
在彈出EditForm設(shè)置GridEditFormSettings控制通過(guò)的PopUpSettings屬性對(duì)象。 它暴露3屬性:
高度 -定義的百分比或彈出高度的像素
寬度-定義寬度的百分比或彈出像素
滾動(dòng)條-定義是否應(yīng)顯示滾動(dòng)條并在編輯表格。此設(shè)置優(yōu)先級(jí)較高,因此,如果高度設(shè)置,但不顯示垂直滾動(dòng)條的內(nèi)
容需要更多的空間,在彈出會(huì)被重新調(diào)整,以適應(yīng)整個(gè)內(nèi)容。默認(rèn)值為 None。
設(shè)置下DataSet , 方便后面調(diào)用.
public DataSet MenuData
? ? {
? ? ? ? get
? ? ? ? {
? ? ? ? ? ? object obj = this.Session["MenuData"];
? ? ? ? ? ? if (obj != null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? return (DataSet)obj;
? ? ? ? ? ? }
? ? ? ? ? ? DataSet menuData = new DataSet();
? ? ? ? ? ? String ConnString = ConfigurationManager.ConnectionStrings
["ConnectionString"].ConnectionString;
? ? ? ? ? ? SqlConnection conn = new SqlConnection(ConnString);
? ? ? ? ? ? SqlDataAdapter adapter = new SqlDataAdapter();
? ? ? ? ? ? adapter.SelectCommand = new SqlCommand("SELECT * FROM Menu", conn);
? ? ? ? ? ? adapter.Fill(menuData, "Menu");
? ? ? ? ? ? this.Session["MenuData"] = menuData;
? ? ? ? ? ? return menuData;
? ? ? ? }
? ? }
綁定RadGird,在NeedDataSource事件里綁定~
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
? ? {
? ? ? ? this.RadGrid1.DataSource = MenuData;
? ? ? ? this.MenuData.Tables["Menu"].PrimaryKey = new DataColumn[] { this.MenuData.Tables
["Menu"].Columns["MenuID"] };//設(shè)置主鍵
? ? }
UpdateCommand事件里實(shí)現(xiàn)修改.
protected void RadGrid1_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
? ? {
? ? ? ? GridEditableItem editedItem = e.Item as GridEditableItem;
? ? ? ? DataRow[] changedRows = MenuData.Tables["Menu"].Select("MenuID = " +?
editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["MenuID"]);
? ? ? ? if (changedRows.Length != 1)
? ? ? ? {
? ? ? ? ? ? e.Canceled = true;
? ? ? ? ? ? return;
? ? ? ? }
? ? ? ? Hashtable newValues = new Hashtable();
? ? ? ? newValues["SortNo"] = (editedItem.FindControl("txtSortNo") as TextBox).Text;
? ? ? ? newValues["ParentID"] = (editedItem.FindControl("txtParentID") as TextBox).Text;
? ? ? ? newValues["Name"] = (editedItem.FindControl("txtName") as TextBox).Text;
? ? ? ? newValues["IsEnable"] = (editedItem.FindControl("ckEnable") as CheckBox).Checked;
? ? ? ? newValues["IconUrl"] = (editedItem.FindControl("txtIconUrl") as TextBox).Text;
? ? ? ? newValues["Url"] = (editedItem.FindControl("txtUrl") as TextBox).Text;
? ? ? ? newValues["MenuID"] = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]
["MenuID"];
? ? ? ? changedRows[0].BeginEdit();
? ? ? ? try
? ? ? ? {
? ? ? ? //遍歷,把數(shù)據(jù)存到DataRow
? ? ? ? ? ? foreach (DictionaryEntry entry in newValues)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? changedRows[0][(string)entry.Key] = entry.Value;
? ? ? ? ? ? }
? ? ? ? ? ? changedRows[0].EndEdit();
? ? ? ? ? ? this.MenuData.AcceptChanges(); //更新數(shù)據(jù)源
? ? ? ? ? ? MSSQL.SqlServerHelper.UpdateMenu(); //更新數(shù)據(jù)庫(kù)方法
? ? ? ? }
? ? ? ? catch (Exception ex)
? ? ? ? {
? ? ? ? ? ? changedRows[0].CancelEdit();
? ? ? ? ? ? RadGrid1.Controls.Add(new LiteralControl("Unable to update Employees. Reason: " +?
ex.Message));
? ? ? ? ? ? e.Canceled = true;
? ? ? ? }
? ? ? ? RadGrid1.MasterTableView.Items[e.Item.ItemIndex].Edit = false;//關(guān)閉當(dāng)前修改窗口
? ? }
?RadGrid1_InsertCommand 增加~
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
? ? {
? ? ? ? GridEditableItem editedItem = e.Item as GridEditableItem;
? ? ? ? DataRow newRow = MenuData.Tables["Menu"].NewRow();
? ? ? ? Hashtable newValues = new Hashtable();
? ? ? ? newValues["SortNo"] = (editedItem.FindControl("txtSortNo") as TextBox).Text;
? ? ? ? newValues["ParentID"] = (editedItem.FindControl("txtParentID") as TextBox).Text;
? ? ? ? newValues["Name"] = (editedItem.FindControl("txtName") as TextBox).Text;
? ? ? ? newValues["IsEnable"] = (editedItem.FindControl("ckEnable") as CheckBox).Checked;
? ? ? ? newValues["IconUrl"] = (editedItem.FindControl("txtIconUrl") as TextBox).Text;
? ? ? ? newValues["Url"] = (editedItem.FindControl("txtUrl") as TextBox).Text;
? ? //獲取表Menu最后一個(gè)的ID + 1?
? ? ? ? newValues["MenuID"] = (int)this.MenuData.Tables["Menu"].Rows[this.MenuData.Tables
["Menu"].Rows.Count - 1]["MenuID"] + 1;
? ? ? ? try
? ? ? ? {
? ? ? ? ? ? foreach (DictionaryEntry entry in newValues)
? ? ? ? ? ? ? ? newRow[(string)entry.Key] = entry.Value;
? ? ? ? ? ? this.MenuData.Tables["Menu"].Rows.Add(newRow);
? ? ? ? ? ? this.MenuData.Tables["Menu"].AcceptChanges();
? ? ? ? ? ? MSSQL.SqlServerHelper.Insert();
? ? ? ? }
? ? ? ? catch (Exception ex)
? ? ? ? {
? ? ? ? ? ? e.Canceled = true;
? ? ? ? }
? ? }
RadGrid1_DeleteCommand 刪除~
string ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["MenuID"].ToString();
? ? ? ? DataSet ds = (DataSet)Session["MenuData"];
? ? ? ? if (ds.Tables["Menu"].Rows.Find(ID) != null)
? ? ? ? {
? ? ? ? ? ? ds.Tables["Menu"].Rows.Find(ID).Delete();
? ? ? ? ? ? ds.Tables["Menu"].AcceptChanges();
? ? ? ? ? ? MSSQL.SqlServerHelper.DeleteMenu(ID);
? ? ? ? ? ? Session["DataSource"] = ds.Tables["Menu"];
? ? ? ? }
前臺(tái)頁(yè)面一些效果.
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
? ? ? ? <AjaxSettings>
? ? ? ? ? ? <telerik:AjaxSetting AjaxControlID="RadGrid1">
? ? ? ? ? ? ? ? <UpdatedControls>
? ? ? ? ? ? ? ? ? ? <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
? ? ? ? ? ? ? ? </UpdatedControls>
? ? ? ? ? ? </telerik:AjaxSetting>
? ? ? ? </AjaxSettings>
? ? </telerik:RadAjaxManager>
雙擊行, 編輯狀態(tài):
在RadGrid里加入
<ClientSettings>
? ? ? ?<ClientEvents OnRowDblClick="RowDblClick" />
</ClientSettings>
JS加入:
function RowDblClick(sender, eventArgs) {
? ? ? ?sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
}
細(xì)節(jié):
因?yàn)槭怯⑽牡?所以可以找到****Text去改文本,那樣提示或文本都是中文的了 - -,
<%# (Container is GridEditFormInsertItem) ? "插入" : "更新" %> . 因?yàn)椴迦敫掠玫氖峭粋€(gè)窗口~ 所以用
這句判斷是插入還是更新~
========
Telerik RadGrid - SessionDataSource
Telerik_Web_UI
第一天-Telerik RadGrid 數(shù)據(jù)展現(xiàn), 使用官方的SessionDataSource~
1.導(dǎo)入<%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>
2.配置SessionDataSource選項(xiàng)
1 <sds:SessionDataSource ID="SessionDataSource1" ConnectionString="<%$?
ConnectionStrings:NorthwindConnectionString %>"
2 ? ? ? ? ProviderName="System.Data.SqlClient"
3 ? ? ? ? SelectCommand="SELECT * FROM [Products]" runat="server" PrimaryKeyFields="ProductID">
4 </sds:SessionDataSource>
3.RadGrid 設(shè)置 DataSourceID="SessionDataSource1"
這時(shí)你會(huì)發(fā)現(xiàn),還需要(SessionDataSource.cs),這個(gè)文件在安裝目錄\Live Demos\App_Code\下面.
========
Telerik RadUpload 文件類(lèi)型驗(yàn)證
?你可以使用RadUpload與ASP.NET的自定義驗(yàn)證器。 CustomValidator驗(yàn)證同時(shí)支持客戶端和服務(wù)器端驗(yàn)證。
驗(yàn)證客戶端的好處是可以防止的CustomValidator驗(yàn)證時(shí)提交的文件有選擇的客戶端驗(yàn)證函數(shù)認(rèn)為無(wú)效的頁(yè)面。驗(yàn)證
功能可以使用validateExtensions()客戶端的方法來(lái)驗(yàn)證客戶端上的文件擴(kuò)展名。選定的文件必須轉(zhuǎn)移到服務(wù)器
才能的尺寸或MIME類(lèi)型的驗(yàn)證。
驗(yàn)證服務(wù)器端的優(yōu)點(diǎn)是您可以訪問(wèn)文件,如大小或MIME類(lèi)型,甚至檢查文件內(nèi)容的信息。自定義驗(yàn)證器的
ServerValidate事件發(fā)生后,RadUpload ValidatingFile事件,并有完整的驗(yàn)證。
?當(dāng)使用一個(gè)CustomValidator驗(yàn)證,驗(yàn)證器的ControlToValidate屬性RadUpload不得設(shè)置!
先上圖:
Upload控件需要幾個(gè)js的支持, Telerik 的 dll 自帶了需要的js.
<telerik:RadScriptManager ID="ScriptManager1" runat="server">
? ? ? ? <Scripts>
? ? ? ? ? ? <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
? ? ? ? ? ? <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
? ? ? ? ? ? <asp:ScriptReference Assembly="Telerik.Web.UI"?
Name="Telerik.Web.UI.Common.jQueryInclude.js" />
? ? ? ? </Scripts>
? ? </telerik:RadScriptManager>
<div class="MainWrap">
? ? ? ? <div class="TopWrap">
? ? ? ? ? ? <div class="Holder">
? ? ? ? ? ? ? ? <telerik:RadAsyncUpload runat="server" ID="RadAsyncUpload1"?
AllowedFileExtensions="jpg,jpeg,png,gif"
? ? ? ? ? ? ? ? ? ? MaxFileSize="1048576" OnClientValidationFailed="validationFailed"?
OnValidatingFile="RadAsyncUpload1_ValidatingFile"
? ? ? ? ? ? ? ? ? ? OnFileUploaded="RadAsyncUpload1_FileUploaded" InputSize="42" Skin="Windows7" >
? ? ? ? ? ? ? ? </telerik:RadAsyncUpload>
? ? ? ? ? ? ? ? <asp:Button runat="server" ID="BtnSubmit" Text="上傳" />
? ? ? ? ? ? ? ? <p>
? ? ? ? ? ? ? ? ? ? 選擇要上傳的圖片 (jpg, jpeg, png, gif)
? ? ? ? ? ? ? ? </p>
? ? ? ? ? ? ? ? <p>
? ? ? ? ? ? ? ? ? ? 圖片最大不能超過(guò) 1M 大小.
? ? ? ? ? ? ? ? </p>
? ? ? ? ? ? ? ? <div class="ErrorHolder">
? ? ? ? ? ? ? ? </div>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="Holder Right">
? ? ? ? ? ? ? ? <asp:Panel runat="server" ID="ResultsPanel" Visible="false">
? ? ? ? ? ? ? ? ? ? <asp:Panel ID="ValidFiles" Visible="false" runat="server">
? ? ? ? ? ? ? ? ? ? ? ? <p>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <strong>圖像保存到目標(biāo)文件夾: ?/File/</strong>
? ? ? ? ? ? ? ? ? ? ? ? </p>
? ? ? ? ? ? ? ? ? ? </asp:Panel>
? ? ? ? ? ? ? ? ? ? <asp:Panel ID="InvalidFiles" Visible="false" runat="server">
? ? ? ? ? ? ? ? ? ? ? ? <p>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <strong>下面的圖片不被保存,由于超過(guò)最大大小:</strong>
? ? ? ? ? ? ? ? ? ? ? ? </p>
? ? ? ? ? ? ? ? ? ? </asp:Panel>
? ? ? ? ? ? ? ? </asp:Panel>
? ? ? ? ? ? </div>
? ? ? ? ? ? <div class="BottomWrap">
? ? ? ? ? ? </div>
? ? ? ? </div>
? ? </div>
const int MaxTotalBytes = 1048576; // 1 MB
? ? int totalBytes;
? ? protected void Page_Load(object sender, EventArgs e)
? ? {
? ? ? ? if (IsPostBack)
? ? ? ? {
? ? ? ? ? ? ResultsPanel.Visible = true;
? ? ? ? }
? ? }
? ? public void RadAsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
? ? {
? ? ? ? Label fileName = new Label();
? ? ? ? fileName.Text = e.File.FileName;
? ? ? ? e.File.SaveAs(Server.MapPath("../file/"+e.File.FileName),true);//保存文件
? ? ? ? if (e.IsValid)
? ? ? ? {
? ? ? ? ? ? ValidFiles.Visible = true;
? ? ? ? ? ? ValidFiles.Controls.Add(fileName);
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? InvalidFiles.Visible = true;
? ? ? ? ? ? InvalidFiles.Controls.Add(fileName);
? ? ? ? }
? ? }
? ? public void RadAsyncUpload1_ValidatingFile(object sender,?
Telerik.Web.UI.Upload.ValidateFileEventArgs e)
? ? {
? ? ? ? if (totalBytes < MaxTotalBytes)
? ? ? ? {
? ? ? ? ? ? // 沒(méi)有達(dá)到限制的總字節(jié)數(shù),運(yùn)行文件上傳
? ? ? ? ? ? e.IsValid = true;
? ? ? ? ? ? totalBytes += e.UploadedFile.ContentLength;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? // 達(dá)到限制的總字節(jié)數(shù),放棄文件上傳
? ? ? ? ? ? e.IsValid = false;
? ? ? ? }
? ? }
========
總結(jié)
以上是生活随笔為你收集整理的telerik学习总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ajax技术原理 F7300178 q
- 下一篇: 10kv电压互感器型号_10KV电压互感