telerik学习总结
生活随笔
收集整理的這篇文章主要介紹了
telerik学习总结
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Telerik
Telerik 是保加利亞的一個軟件公司,專注于微軟.Net平臺的表示層與內(nèi)容管理控件。Telerik 提供高度穩(wěn)定性和豐富性能的組件產(chǎn)品,并可應(yīng)用在非常嚴格的環(huán)境中。現(xiàn)在 擁有 Microsoft, HP, Alcoa, BP, Harper Collins,?
Siemens, T-Mobile, HJ Heinz和一些最主要的教育機構(gòu)和很多政府機關(guān)等客戶。
? ? ? ?telerik 的 r.a.d.controls 套裝是一款最具革命性和廣泛性的開發(fā)工具集,它主要針對專業(yè)級的 ASP.NET?
開發(fā),適用于 AJAX, Atlas 、Visual Studio .NET 2005 、Visual Studio 2008 及 ASP.NET 3.5。通過該產(chǎn)品的
強大功能,開發(fā)者可以開發(fā)出功能豐富、適應(yīng)標準廣泛,與交互瀏覽器兼容的網(wǎng)絡(luò)應(yīng)用程序。
? ? ? ?2012年,Telerik新推出了Icenium服務(wù),該服務(wù)是一個集成的云環(huán)境(Integrated Cloud Enviroment,ICE
)。
? ? ? ?數(shù)十年來,IDE一直是應(yīng)用開發(fā)的基礎(chǔ),微軟Visual Studio,Eclipse、NetBeans等都是IDE的代表。IDE的
問題是開發(fā)和部署有許多繁瑣的要求,在環(huán)境和客戶端種類繁多的移動時代已經(jīng)顯得支撐不足。
? ? ? ?針對IDE的這些弊端,Icenium把所有移動應(yīng)用開發(fā)都搬到了云上面,把IDE中的SDK、編譯器、測試、調(diào)試、
數(shù)字認證等,通通都變成了云服務(wù),這樣的話開發(fā)者就可以在任何設(shè)備、任何開發(fā)環(huán)境上開發(fā)應(yīng)用,從而擺脫物理
環(huán)境或特定平臺的束縛。
? ? ? ?Icenium具有一次開發(fā)、支持多種部署的能力。該服務(wù)可通過瀏覽器訪問,用戶可運用其HTML5、CSS及
JavaScript技能來創(chuàng)建部署應(yīng)用,所創(chuàng)建的原生應(yīng)用可以在蘋果iOS平臺和Google Android平臺運行。
? ? ? ?在Icenium中,開發(fā)者可利用Apache Cordova開發(fā)具備拍照、加速計、定位等功能的混合型應(yīng)用。可訪問
GitHub等給予URL的Git容器。集成的版本控制允許保存代碼,并在云端進行版本化,從而可以在任何時間任何地方
訪問這些代碼。
? ? ? ?cenium還有一個集成的模擬環(huán)境,讓開發(fā)者無需部署就可以看到應(yīng)用在設(shè)備端的樣子。Icenium還允許開發(fā)
者了解應(yīng)用在不同外形因素下的樣子。開發(fā)者可以在數(shù)分鐘之內(nèi)實現(xiàn)傳統(tǒng)方法需要半小時或更多的時間才能完成的
事情。
? ? ? ?與Icenium類似的服務(wù)還有PhoneGap和Kii Cloud。這些服務(wù)降低了開發(fā)復(fù)雜性,加快了開發(fā)速度,對IDE缺
乏深入了解的開發(fā)者以及希望加速應(yīng)用部署及有效管理開發(fā)的企業(yè)來說都具有很大的吸引力。
? ? ? ?Icenium于去年夏天開始進行不公開beta測試,現(xiàn)在已經(jīng)開放公測至明年5月份,有興趣的同學(xué)不妨到其網(wǎng)站
試試。
========
Telerik控件使用
方法/步驟
1
RadGrid添加序號列
<telerik:GridTemplateColumn HeaderText="序號列">
? ? ? ? ? ? ? ? ? ? <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時顯示窗口
? ? 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" 點擊文本框時顯示時間panel
b.DateFormat 格式化時間
========
一個Asp.net MVC 控件項目分析---Telerik.Web.Mvc
? ? ? 在寫本文之前,本人一直抱著‘不宜’在asp.net MVC框架下搞什么控件開發(fā)的想法,因為一提到控件就會讓人想起‘事件’,‘VIEWSTATE’等一些問題,而asp.net MVC下是Controller, Action, Viewpage, Filter等特性
的‘天下’。所以總感覺‘驢唇對不上馬嘴’。
? ? ? 但直到前陣子在郵箱中收到了關(guān)于telerik關(guān)于MVC框架擴展的一些信息之后,才發(fā)現(xiàn)這家商業(yè)控件公司也開
始打MVC的主意了。而這個項目(開源)就是該公司在理解了asp.net mvc的基礎(chǔ)上所做的一些嘗試,當(dāng)然其所實現(xiàn)
的所謂控件與之前我們在項目中所開發(fā)或使用的web服務(wù)器控件有很大的不同,可以說是拋棄了以往的設(shè)計方式。盡
管目前它的這種做法我心里還打著問號,但必定是一種嘗試(不管你贊同還是不贊同)。下面就做一個簡單的分析
,希望能給研究MVC架構(gòu)的朋友提供一些的思考。
? ? ? 首先要聲明的是該開源項目中所使用的js就是jquery,而那些顯示效果也基本上就是基于jquery中的那件插
件為原型,并進行相應(yīng)的屬性封裝,以便于在viewpage中用c#等語言進行聲明綁定。下面就其中一些控件的顯示截
圖:
? ? ? telerik_mvc_accordion
? ? ?telerik_mvc_date
? ? ?telerik_mvc_slider
? ? ? telerik_mvc_progressbar
? ? ? ?在該開源項目中,所有控件均基于jQueryViewComponentBase (abstract 類型),但其自身屬性并不多,而
所有的控件基類屬性都被jQueryViewComponentBase 的父類ViewComponentBase所定義,下面以控件中
的“Accordion(屬性頁控件)”為例進行說明,見下圖:
telerik_mvc_baseclass
? ? ? 上圖中左側(cè)的就是ViewComponentBase類,其定義了多數(shù)控件屬性,比如js腳本名稱和路徑以及相關(guān)樣式以及
最終的html元素輸出方法,因為其類也是抽象類,所以其中大部分方法均為定義,而未進行具體實現(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)前視圖的上下文,將會在子類中使用</param>
? ? ? ? /// <param name="clientSideObjectWriterFactory">傳入當(dāng)前所使用的Writer工廠實例.通過子類注入,
子類最終延伸到相對應(yīng)的控件實例</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();
? ? ? ? }?
? ? 通過上述的構(gòu)造方法,就可以將控件的一些通用默認屬性值進行初始化了。
? ? 下面以“Accordion”的源碼來分析一下,這里還是從構(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),以實現(xiàn)向基類構(gòu)造
方法傳參,也就是實現(xiàn)了上面所說的將當(dāng)前控件所使用的viewContext,clientSideObjectWriterFactory傳遞到基
類ViewComponentBase 中去。(注:最終的clientSideObjectWriterFactory為ClientSideObjectWriterFactory實
例類型)。
? ? ? 當(dāng)然,因為該控件的中相應(yīng)屬性比較簡單,只是一些set,get語法,所以就不過多介紹了,相信做過控件開發(fā)
的對這些再熟悉不過了。
? ? ? 下面主要介紹一下其write html元素時所使用的方法,如下:
?/// <summary>
? ? ? /// 創(chuàng)建并寫入初始化腳本對象和相應(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 類型實例)中被綁定了相關(guān)的控件屬性,并通過其類
的WriteInitializationScript(writer)進行腳本的輸出。而基本類的相應(yīng)方法如下: ? ?
? ?/// <summary>
? ? ? /// Writes the initialization script.
? ? ? /// </summary>
? ? ? /// <param name="writer">The writer.</param>
? ? ? public virtual void WriteInitializationScript(TextWriter writer)
? ? ? {
? ? ? }?
? ? ? 大家看到該方法為空,但其又是如何運行起來的呢,這里先賣個關(guān)子,稍后再說。接著再看一下另一個方法
: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)前所選屬性頁標簽(GetSelectedItem()方法),然后用foreach方法對屬性頁標簽集合進
行遍歷,并判斷當(dāng)前屬性頁是否就是被選中的屬性頁,并綁定上相應(yīng)的css屬性。其最終也是調(diào)用相應(yīng)的基類方法進
行輸出。當(dāng)然這里基類方法也是為空,呵呵。
? ? ?準備好了這個控件類之后,Telerik還為Accordion控件‘準備’了一些輔助組件,比如屬性頁組件
(AccordionItem),以及相關(guān)的組件構(gòu)造器(AccordionItemBuilder,AccordionBuilder),這樣我們就可以通過
這些構(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>
? ? ? /// 指定一個屬性頁選項
? ? ? /// </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>
? ? ? /// 屬性頁動態(tài)效果顯示名稱(鼠標在屬性頁移入移出時)
? ? ? /// </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ā)的屬性頁事件名稱.
? ? ? /// </summary>
? ? ? /// <param name="eventName">Name of the event.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder OpenOn(string eventName)
? ? ? {
? ? ? ? ? Component.OpenOn = eventName;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 所使用的Icons名稱.
? ? ? /// </summary>
? ? ? /// <param name="name">The name.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder Icon(string name)
? ? ? {
? ? ? ? ? Component.Icon = name;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 被選中的屬性頁所使用的Icons 名稱
? ? ? /// </summary>
? ? ? /// <param name="name">The name.</param>
? ? ? /// <returns></returns>
? ? ? public virtual AccordionBuilder SelectedIcon(string name)
? ? ? {
? ? ? ? ? Component.SelectedIcon = name;
? ? ? ? ? return this;
? ? ? }
? ? ? /// <summary>
? ? ? /// 當(dāng)屬性頁發(fā)生變化時要傳遞的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;
? ? ? }
? }?
?
? ? ?對于上面的OnChange方法,可以使用下面的方法將相應(yīng)的js腳本傳入并執(zhí)行
.OnChange(() =>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {%>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? function(event, ui)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? $('#trace').append('Change fired: ' + new Date() +?
'<br/>');
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <%}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? )?
? ? 這樣,當(dāng)屬性頁發(fā)生變化時,就會在頁面的指定區(qū)域?qū)⒆兓瘯r間顯示出來了,如下圖:
? ?telerik_mvc_onchange
??
? ? Telerik在jQueryViewComponentFactory中對項目中每一個控件提供了一個方法用以初始化相應(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)));
? ? ?}?
? ? 而對于其在VIEW中的使用,則通過擴展方法來加以聲明:
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);
? ? ? ?}
? ?}?
? ? 這樣在頁面視圖中,我們這可以使用下面的寫法來構(gòu)造一個Accordion控件了:
<% Html.jQuery().Accordion()
? ? ? ? ? ? ? ? ? .Name("myAccordion")
? ? ? ? ? ? ? ? ? .Animate("bounceslide")
? ? ? ? ? ? ? ? ? .Items(parent =>
? ……?
?
? ? ?上面只是介紹了前臺和底層代碼如果顯示的問題,但還沒有解釋之前所說的WriteInitializationScript
(TextWriter writer)方法以及WriteHtml()
方法如何被調(diào)用的問題,正如之前所看到的,因為Accordion的基類ViewComponentBase中未實現(xiàn)具體的代碼,所以
這里我們要將注意力轉(zhuǎn)移到 jQueryViewComponentFactory中,請看如下代碼:?
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;
? ? ? ?}?
? ? ?上面的方法其實就是之前在該類方法Accordion()中所調(diào)用并執(zhí)行的:
? ? ?return new AccordionBuilder(Create(() => new Accordion(ViewContext,?
clientSideObjectWriterFactory)));
? ? ?通過該方法,就可以將該控件及其相關(guān)組件信息注冊到相應(yīng)的視圖中。因為我們比較關(guān)注WriteHtml()方法,
所以這里就直接分析一下這一行代碼: ? ?
? ? ?ScriptRegistrar().ToRegistrar().Register(component);?
? ? ?ScriptRegistrar類中的Register方法承擔(dān)著將當(dā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)就會調(diào)用Render()方法將其顯示出來(注:該方法與以前web控件
開發(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);
?
? ? ? 其所實現(xiàn)的功能如下: ??
? ? ? /// <summary>
? ? ? /// 寫出所有腳本資源和腳本 statements.
? ? ? /// </summary>
? ? ? /// <param name="writer">The writer.</param>
? ? ? protected virtual void Write(TextWriter writer)
? ? ? {
? ? ? ? ? WriteScriptSources(writer);
? ? ? ? ? WriteScriptStatements(writer);
? ? ? }?
? ? ? ?而就是WriteScriptStatements這行代碼開始執(zhí)行之前所說的那個WriteInitializationScript(TextWriter?
writer)。而WriteHtml()方法的執(zhí)行入口要更加復(fù)雜一些,因為Telerik提供了ViewComponentBuilderBase這個類來
進行視圖組件的構(gòu)造,而該類中的Render方法就是對相應(yīng)組件的Render方法(組件中已定義)進行調(diào)用,如下:
? ? /// <summary>
? ? /// Renders the component.
? ? /// </summary>
? ? public virtual void Render()
? ? {
? ? ? ? Component.Render();
? ? }?
? ? ? 而之前的“Accordion”控件是繼承自ViewComponentBase類,所以相應(yīng)組件的Render方法就在該類中進行了
聲明定義,如下:
? ? ?/// <summary>
? ? ?/// Renders the component.
? ? ?/// </summary>
? ? ?public void Render()
? ? ?{
? ? ? ? ?EnsureRequired();
? ? ? ? ?WriteHtml();
? ? ?}?
? ? ? 大家看到了第二行代碼了吧,這就是我們之前看到的那個方法,也就是Accordion組件中WriteHtml()重寫方
法的調(diào)用入口。
? ? ? 繞了這么一大圈,才把這個流程理清,是不是有些暈了。的確,剛開始接觸時我也有點暈,但暈呀暈呀就‘
暈過去了’,現(xiàn)在再回頭看起來感常見其整體的架構(gòu)思路還是很清晰的。可以說有了這瓶酒墊底,再分析該項目中
的其它控件就‘如魚得水’了。
? ? ? 最后不妨總結(jié)一下:
? ? ? 該項目中對asp.net mvc控件下的開發(fā)做了一次嘗試,但如果之前做過控件特別是web服務(wù)器端控件開發(fā)的朋
友,可以看出項目中有非常重的web控件開發(fā)味道,基本連方法名稱都有一定的重疊。
? ? ? 另外就是其自身還是引用了組件對象模型的概念,就拿屬性頁控件來說,就將其分為Accordion和
AccordionItem兩種類型,其中可以將Accordion看成是AccordionItem的集合封裝(包括遍歷操作),而這里
AccordionItem就成了Accordion的一個組件,而Accordion又是當(dāng)前view中的一個組件。而組件開發(fā)一直是.net平臺
上所倡導(dǎo)的。其優(yōu)勢在于可復(fù)用,維護方便,簡化復(fù)雜問題等。
? ? ? 好了,今天的內(nèi)容就先到這里了。
http://www.cnblogs.com/daizhj/archive/2009/09/09/1562966.html
========
Telerik RadGrid - DataSet (增刪查改)
Telerik RadGrid 數(shù)據(jù)展現(xiàn)、修改、刪除、增加, 數(shù)據(jù)源使用后臺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="添加新項"?
? ? ? ? ? ? ? ? RefreshText="更新"></CommandItemSettings>
? ? ? ? ? ? <Columns>
? ? ? ? ? ? ? ? <telerik:GridEditCommandColumn EditText="修改">
? ? ? ? ? ? ? ? </telerik:GridEditCommandColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="MenuID" HeaderText="菜單序號"?
DataField="MenuID">
? ? ? ? ? ? ? ? ? ? <HeaderStyle Width="60px"></HeaderStyle>
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="SortNo" HeaderText="排序序號"?
DataField="SortNo">
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="ParentID" HeaderText="父節(jié)點"?
DataField="ParentID">
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="Name" HeaderText="名稱" DataField="Name">
? ? ? ? ? ? ? ? </telerik:GridBoundColumn>
? ? ? ? ? ? ? ? <telerik:GridBoundColumn UniqueName="IconUrl" HeaderText="圖標路徑"?
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="修改 菜單序號: {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>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 排序序號:
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:TextBox ID="txtSortNo" Text='<%# Bind( "SortNo") %>'?
runat="server">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:TextBox>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 父節(jié)點:
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? <asp:TextBox ID="txtParentID" Text='<%# Bind( "ParentID") %>'?
runat="server">
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? </asp:TextBox>
? ? ? ? ? ? ? ? ? ? ? ? ? ? </td>
? ? ? ? ? ? ? ? ? ? ? ? </tr>
? ? ? ? ? ? ? ? ? ? ? ? <tr>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <td>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 名稱:
? ? ? ? ? ? ? ? ? ? ? ? ? ? </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>
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 圖標路徑:
? ? ? ? ? ? ? ? ? ? ? ? ? ? </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="首頁" LastPageToolTip="尾頁" NextPagesToolTip="下一頁"?
? ? ? ? ? ? ? ? NextPageToolTip="下一頁"
? ? ? ? ? ? ? ? PageSizeLabelText="頁數(shù):" PrevPagesToolTip="上一頁" PrevPageToolTip="上一頁" />
? ? ? ? </MasterTableView>
? ? </telerik:RadGrid>
ShowStatusBar="true" ?//顯示工具欄
EditFormType="Template" ?//所有類型的編輯形式彈出可以顯示在編輯類型AutoGenerated、WebUserControl和
Template
在彈出EditForm設(shè)置GridEditFormSettings控制通過的PopUpSettings屬性對象。 它暴露3屬性:
高度 -定義的百分比或彈出高度的像素
寬度-定義寬度的百分比或彈出像素
滾動條-定義是否應(yīng)顯示滾動條并在編輯表格。此設(shè)置優(yōu)先級較高,因此,如果高度設(shè)置,但不顯示垂直滾動條的內(nèi)
容需要更多的空間,在彈出會被重新調(diào)整,以適應(yīng)整個內(nèi)容。默認值為 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事件里實現(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ù)庫方法
? ? ? ? }
? ? ? ? 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最后一個的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"];
? ? ? ? }
前臺頁面一些效果.
<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());
}
細節(jié):
因為是英文的,所以可以找到****Text去改文本,那樣提示或文本都是中文的了 - -,
<%# (Container is GridEditFormInsertItem) ? "插入" : "更新" %> . 因為插入更新用的是同一個窗口~ 所以用
這句判斷是插入還是更新~
========
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選項
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"
這時你會發(fā)現(xiàn),還需要(SessionDataSource.cs),這個文件在安裝目錄\Live Demos\App_Code\下面.
========
Telerik RadUpload 文件類型驗證
?你可以使用RadUpload與ASP.NET的自定義驗證器。 CustomValidator驗證同時支持客戶端和服務(wù)器端驗證。
驗證客戶端的好處是可以防止的CustomValidator驗證時提交的文件有選擇的客戶端驗證函數(shù)認為無效的頁面。驗證
功能可以使用validateExtensions()客戶端的方法來驗證客戶端上的文件擴展名。選定的文件必須轉(zhuǎn)移到服務(wù)器
才能的尺寸或MIME類型的驗證。
驗證服務(wù)器端的優(yōu)點是您可以訪問文件,如大小或MIME類型,甚至檢查文件內(nèi)容的信息。自定義驗證器的
ServerValidate事件發(fā)生后,RadUpload ValidatingFile事件,并有完整的驗證。
?當(dāng)使用一個CustomValidator驗證,驗證器的ControlToValidate屬性RadUpload不得設(shè)置!
先上圖:
Upload控件需要幾個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>
? ? ? ? ? ? ? ? ? ? 圖片最大不能超過 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>圖像保存到目標文件夾: ?/File/</strong>
? ? ? ? ? ? ? ? ? ? ? ? </p>
? ? ? ? ? ? ? ? ? ? </asp:Panel>
? ? ? ? ? ? ? ? ? ? <asp:Panel ID="InvalidFiles" Visible="false" runat="server">
? ? ? ? ? ? ? ? ? ? ? ? <p>
? ? ? ? ? ? ? ? ? ? ? ? ? ? <strong>下面的圖片不被保存,由于超過最大大小:</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)
? ? ? ? {
? ? ? ? ? ? // 沒有達到限制的總字節(jié)數(shù),運行文件上傳
? ? ? ? ? ? e.IsValid = true;
? ? ? ? ? ? totalBytes += e.UploadedFile.ContentLength;
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? // 達到限制的總字節(jié)數(shù),放棄文件上傳
? ? ? ? ? ? e.IsValid = false;
? ? ? ? }
? ? }
========
總結(jié)
以上是生活随笔為你收集整理的telerik学习总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ajax技术原理 F7300178 q
- 下一篇: 相空间重构中延迟时间tau的选择:自相关