| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093 |
- //
- // System.Web.UI.WebControls.GridView.cs
- //
- // Authors:
- // Lluis Sanchez Gual ([email protected])
- //
- // (C) 2005 Novell, Inc (http://www.novell.com)
- //
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- #if NET_2_0
- using System;
- using System.Collections;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Web.UI;
- using System.Security.Permissions;
- using System.Text;
- using System.IO;
- using System.Reflection;
- namespace System.Web.UI.WebControls
- {
- [SupportsEventValidation]
- [DesignerAttribute ("System.Web.UI.Design.WebControls.GridViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
- [ControlValuePropertyAttribute ("SelectedValue")]
- [DefaultEventAttribute ("SelectedIndexChanged")]
- [AspNetHostingPermissionAttribute (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- [AspNetHostingPermissionAttribute (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
- public class GridView: CompositeDataBoundControl, ICallbackEventHandler, ICallbackContainer, IPostBackEventHandler, IPostBackContainer
- {
- Table table;
- GridViewRowCollection rows;
- GridViewRow bottomPagerRow;
- GridViewRow topPagerRow;
-
- IOrderedDictionary currentEditRowKeys;
- IOrderedDictionary currentEditNewValues;
- IOrderedDictionary currentEditOldValues;
-
- ITemplate pagerTemplate;
- ITemplate emptyDataTemplate;
-
- PropertyDescriptor[] cachedKeyProperties;
-
- // View state
- DataControlFieldCollection columns;
- PagerSettings pagerSettings;
-
- TableItemStyle alternatingRowStyle;
- TableItemStyle editRowStyle;
- TableItemStyle emptyDataRowStyle;
- TableItemStyle footerStyle;
- TableItemStyle headerStyle;
- TableItemStyle pagerStyle;
- TableItemStyle rowStyle;
- TableItemStyle selectedRowStyle;
- ArrayList _dataKeyArrayList;
- DataKeyArray keys;
- DataKey oldEditValues;
- AutoGeneratedFieldProperties[] autoFieldProperties;
- string [] dataKeyNames = null;
- readonly string[] emptyKeys = new string[0];
-
- private static readonly object PageIndexChangedEvent = new object();
- private static readonly object PageIndexChangingEvent = new object();
- private static readonly object RowCancelingEditEvent = new object();
- private static readonly object RowCommandEvent = new object();
- private static readonly object RowCreatedEvent = new object();
- private static readonly object RowDataBoundEvent = new object();
- private static readonly object RowDeletedEvent = new object();
- private static readonly object RowDeletingEvent = new object();
- private static readonly object RowEditingEvent = new object();
- private static readonly object RowUpdatedEvent = new object();
- private static readonly object RowUpdatingEvent = new object();
- private static readonly object SelectedIndexChangedEvent = new object();
- private static readonly object SelectedIndexChangingEvent = new object();
- private static readonly object SortedEvent = new object();
- private static readonly object SortingEvent = new object();
-
- // Control state
- int pageIndex;
- int selectedIndex = -1;
- int editIndex = -1;
- SortDirection sortDirection = SortDirection.Ascending;
- string sortExpression;
-
- public GridView ()
- {
- }
-
- public event EventHandler PageIndexChanged {
- add { Events.AddHandler (PageIndexChangedEvent, value); }
- remove { Events.RemoveHandler (PageIndexChangedEvent, value); }
- }
-
- public event GridViewPageEventHandler PageIndexChanging {
- add { Events.AddHandler (PageIndexChangingEvent, value); }
- remove { Events.RemoveHandler (PageIndexChangingEvent, value); }
- }
-
- public event GridViewCancelEditEventHandler RowCancelingEdit {
- add { Events.AddHandler (RowCancelingEditEvent, value); }
- remove { Events.RemoveHandler (RowCancelingEditEvent, value); }
- }
-
- public event GridViewCommandEventHandler RowCommand {
- add { Events.AddHandler (RowCommandEvent, value); }
- remove { Events.RemoveHandler (RowCommandEvent, value); }
- }
-
- public event GridViewRowEventHandler RowCreated {
- add { Events.AddHandler (RowCreatedEvent, value); }
- remove { Events.RemoveHandler (RowCreatedEvent, value); }
- }
-
- public event GridViewRowEventHandler RowDataBound {
- add { Events.AddHandler (RowDataBoundEvent, value); }
- remove { Events.RemoveHandler (RowDataBoundEvent, value); }
- }
-
- public event GridViewDeletedEventHandler RowDeleted {
- add { Events.AddHandler (RowDeletedEvent, value); }
- remove { Events.RemoveHandler (RowDeletedEvent, value); }
- }
-
- public event GridViewDeleteEventHandler RowDeleting {
- add { Events.AddHandler (RowDeletingEvent, value); }
- remove { Events.RemoveHandler (RowDeletingEvent, value); }
- }
-
- public event GridViewEditEventHandler RowEditing {
- add { Events.AddHandler (RowEditingEvent, value); }
- remove { Events.RemoveHandler (RowEditingEvent, value); }
- }
-
- public event GridViewUpdatedEventHandler RowUpdated {
- add { Events.AddHandler (RowUpdatedEvent, value); }
- remove { Events.RemoveHandler (RowUpdatedEvent, value); }
- }
-
- public event GridViewUpdateEventHandler RowUpdating {
- add { Events.AddHandler (RowUpdatingEvent, value); }
- remove { Events.RemoveHandler (RowUpdatingEvent, value); }
- }
-
- public event EventHandler SelectedIndexChanged {
- add { Events.AddHandler (SelectedIndexChangedEvent, value); }
- remove { Events.RemoveHandler (SelectedIndexChangedEvent, value); }
- }
-
- public event GridViewSelectEventHandler SelectedIndexChanging {
- add { Events.AddHandler (SelectedIndexChangingEvent, value); }
- remove { Events.RemoveHandler (SelectedIndexChangingEvent, value); }
- }
-
- public event EventHandler Sorted {
- add { Events.AddHandler (SortedEvent, value); }
- remove { Events.RemoveHandler (SortedEvent, value); }
- }
-
- public event GridViewSortEventHandler Sorting {
- add { Events.AddHandler (SortingEvent, value); }
- remove { Events.RemoveHandler (SortingEvent, value); }
- }
-
- protected virtual void OnPageIndexChanged (EventArgs e)
- {
- if (Events != null) {
- EventHandler eh = (EventHandler) Events [PageIndexChangedEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnPageIndexChanging (GridViewPageEventArgs e)
- {
- if (Events != null) {
- GridViewPageEventHandler eh = (GridViewPageEventHandler) Events [PageIndexChangingEvent];
- if (eh != null) {
- eh (this, e);
- return;
- }
- }
- if (!IsBoundUsingDataSourceID)
- throw new HttpException (String.Format ("The GridView '{0}' fired event PageIndexChanging which wasn't handled.", ID));
- }
-
- protected virtual void OnRowCancelingEdit (GridViewCancelEditEventArgs e)
- {
- if (Events != null) {
- GridViewCancelEditEventHandler eh = (GridViewCancelEditEventHandler) Events [RowCancelingEditEvent];
- if (eh != null) {
- eh (this, e);
- return;
- }
- }
- if (!IsBoundUsingDataSourceID)
- throw new HttpException (String.Format ("The GridView '{0}' fired event RowCancelingEdit which wasn't handled.", ID));
- }
-
- protected virtual void OnRowCommand (GridViewCommandEventArgs e)
- {
- if (Events != null) {
- GridViewCommandEventHandler eh = (GridViewCommandEventHandler) Events [RowCommandEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnRowCreated (GridViewRowEventArgs e)
- {
- if (Events != null) {
- GridViewRowEventHandler eh = (GridViewRowEventHandler) Events [RowCreatedEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnRowDataBound (GridViewRowEventArgs e)
- {
- if (Events != null) {
- GridViewRowEventHandler eh = (GridViewRowEventHandler) Events [RowDataBoundEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnRowDeleted (GridViewDeletedEventArgs e)
- {
- if (Events != null) {
- GridViewDeletedEventHandler eh = (GridViewDeletedEventHandler) Events [RowDeletedEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnRowDeleting (GridViewDeleteEventArgs e)
- {
- if (Events != null) {
- GridViewDeleteEventHandler eh = (GridViewDeleteEventHandler) Events [RowDeletingEvent];
- if (eh != null) {
- eh (this, e);
- return;
- }
- }
- if (!IsBoundUsingDataSourceID)
- throw new HttpException (String.Format ("The GridView '{0}' fired event RowDeleting which wasn't handled.", ID));
- }
-
- protected virtual void OnRowEditing (GridViewEditEventArgs e)
- {
- if (Events != null) {
- GridViewEditEventHandler eh = (GridViewEditEventHandler) Events [RowEditingEvent];
- if (eh != null) {
- eh (this, e);
- return;
- }
- }
- if (!IsBoundUsingDataSourceID)
- throw new HttpException (String.Format ("The GridView '{0}' fired event RowEditing which wasn't handled.", ID));
- }
-
- protected virtual void OnRowUpdated (GridViewUpdatedEventArgs e)
- {
- if (Events != null) {
- GridViewUpdatedEventHandler eh = (GridViewUpdatedEventHandler) Events [RowUpdatedEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnRowUpdating (GridViewUpdateEventArgs e)
- {
- if (Events != null) {
- GridViewUpdateEventHandler eh = (GridViewUpdateEventHandler) Events [RowUpdatingEvent];
- if (eh != null) {
- eh (this, e);
- return;
- }
- }
- if (!IsBoundUsingDataSourceID)
- throw new HttpException (String.Format ("The GridView '{0}' fired event RowUpdating which wasn't handled.", ID));
- }
-
- protected virtual void OnSelectedIndexChanged (EventArgs e)
- {
- if (Events != null) {
- EventHandler eh = (EventHandler) Events [SelectedIndexChangedEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnSelectedIndexChanging (GridViewSelectEventArgs e)
- {
- if (Events != null) {
- GridViewSelectEventHandler eh = (GridViewSelectEventHandler) Events [SelectedIndexChangingEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnSorted (EventArgs e)
- {
- if (Events != null) {
- EventHandler eh = (EventHandler) Events [SortedEvent];
- if (eh != null) eh (this, e);
- }
- }
-
- protected virtual void OnSorting (GridViewSortEventArgs e)
- {
- if (Events != null) {
- GridViewSortEventHandler eh = (GridViewSortEventHandler) Events [SortingEvent];
- if (eh != null) {
- eh (this, e);
- return;
- }
- }
- if (!IsBoundUsingDataSourceID)
- throw new HttpException (String.Format ("The GridView '{0}' fired event Sorting which wasn't handled.", ID));
- }
-
-
- [WebCategoryAttribute ("Paging")]
- [DefaultValueAttribute (false)]
- public virtual bool AllowPaging {
- get {
- object ob = ViewState ["AllowPaging"];
- if (ob != null) return (bool) ob;
- return false;
- }
- set {
- ViewState ["AllowPaging"] = value;
- RequireBinding ();
- }
- }
-
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (false)]
- public virtual bool AllowSorting {
- get {
- object ob = ViewState ["AllowSorting"];
- if (ob != null) return (bool) ob;
- return false;
- }
- set {
- ViewState ["AllowSorting"] = value;
- RequireBinding ();
- }
- }
-
- [WebCategoryAttribute ("Styles")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [NotifyParentProperty (true)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public TableItemStyle AlternatingRowStyle {
- get {
- if (alternatingRowStyle == null) {
- alternatingRowStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- alternatingRowStyle.TrackViewState();
- }
- return alternatingRowStyle;
- }
- }
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (false)]
- public virtual bool AutoGenerateEditButton {
- get {
- object ob = ViewState ["AutoGenerateEditButton"];
- if (ob != null) return (bool) ob;
- return false;
- }
- set {
- ViewState ["AutoGenerateEditButton"] = value;
- RequireBinding ();
- }
- }
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (false)]
- public virtual bool AutoGenerateDeleteButton {
- get {
- object ob = ViewState ["AutoGenerateDeleteButton"];
- if (ob != null) return (bool) ob;
- return false;
- }
- set {
- ViewState ["AutoGenerateDeleteButton"] = value;
- RequireBinding ();
- }
- }
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (false)]
- public virtual bool AutoGenerateSelectButton {
- get {
- object ob = ViewState ["AutoGenerateSelectButton"];
- if (ob != null) return (bool) ob;
- return false;
- }
- set {
- ViewState ["AutoGenerateSelectButton"] = value;
- RequireBinding ();
- }
- }
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (true)]
- public virtual bool AutoGenerateColumns {
- get {
- object ob = ViewState ["AutoGenerateColumns"];
- if (ob != null) return (bool) ob;
- return true;
- }
- set {
- ViewState ["AutoGenerateColumns"] = value;
- RequireBinding ();
- }
- }
-
- [UrlPropertyAttribute]
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute ("")]
- [EditorAttribute ("System.Web.UI.Design.ImageUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- public virtual string BackImageUrl {
- get {
- if (ControlStyleCreated)
- return ((TableStyle) ControlStyle).BackImageUrl;
- return String.Empty;
- }
- set {
- ((TableStyle) ControlStyle).BackImageUrl = value;
- }
- }
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public virtual GridViewRow BottomPagerRow {
- get {
- EnsureDataBound ();
- return bottomPagerRow;
- }
- }
-
- [WebCategoryAttribute ("Accessibility")]
- [DefaultValueAttribute ("")]
- [LocalizableAttribute (true)]
- public virtual string Caption {
- get {
- object ob = ViewState ["Caption"];
- if (ob != null) return (string) ob;
- return string.Empty;
- }
- set {
- ViewState ["Caption"] = value;
- RequireBinding ();
- }
- }
-
- [WebCategoryAttribute ("Accessibility")]
- [DefaultValueAttribute (TableCaptionAlign.NotSet)]
- public virtual TableCaptionAlign CaptionAlign
- {
- get {
- object o = ViewState ["CaptionAlign"];
- if(o != null) return (TableCaptionAlign) o;
- return TableCaptionAlign.NotSet;
- }
- set {
- ViewState ["CaptionAlign"] = value;
- RequireBinding ();
- }
- }
- [WebCategoryAttribute ("Layout")]
- [DefaultValueAttribute (-1)]
- public virtual int CellPadding
- {
- get {
- if (ControlStyleCreated)
- return ((TableStyle) ControlStyle).CellPadding;
- return -1;
- }
- set {
- ((TableStyle) ControlStyle).CellPadding = value;
- }
- }
- [WebCategoryAttribute ("Layout")]
- [DefaultValueAttribute (0)]
- public virtual int CellSpacing
- {
- get {
- if (ControlStyleCreated)
- return ((TableStyle) ControlStyle).CellSpacing;
- return 0;
- }
- set {
- ((TableStyle) ControlStyle).CellSpacing = value;
- }
- }
-
- [EditorAttribute ("System.Web.UI.Design.WebControls.DataControlFieldTypeEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- [MergablePropertyAttribute (false)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [DefaultValueAttribute (null)]
- [WebCategoryAttribute ("Misc")]
- public virtual DataControlFieldCollection Columns {
- get {
- if (columns == null) {
- columns = new DataControlFieldCollection ();
- columns.FieldsChanged += new EventHandler (OnFieldsChanged);
- if (IsTrackingViewState)
- ((IStateManager)columns).TrackViewState ();
- }
- return columns;
- }
- }
- [DefaultValueAttribute (null)]
- [WebCategoryAttribute ("Data")]
- [TypeConverter (typeof(StringArrayConverter))]
- [EditorAttribute ("System.Web.UI.Design.WebControls.DataFieldEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
- public virtual string[] DataKeyNames
- {
- get {
- if (dataKeyNames != null)
- return dataKeyNames;
- return emptyKeys;
- }
- set {
- dataKeyNames = value;
- RequireBinding ();
- }
- }
- ArrayList DataKeyArrayList {
- get {
- if (_dataKeyArrayList == null) {
- _dataKeyArrayList = new ArrayList ();
- }
- return _dataKeyArrayList;
- }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual DataKeyArray DataKeys {
- get {
- if (keys == null) {
- keys = new DataKeyArray (DataKeyArrayList);
- if (IsTrackingViewState)
- ((IStateManager) keys).TrackViewState ();
- }
- return keys;
- }
- }
- DataKey OldEditValues {
- get {
- if (oldEditValues == null) {
- oldEditValues = new DataKey (new OrderedDictionary ());
- }
- return oldEditValues;
- }
- }
- [WebCategoryAttribute ("Misc")]
- [DefaultValueAttribute (-1)]
- public virtual int EditIndex {
- get {
- return editIndex;
- }
- set {
- if (value == editIndex)
- return;
- editIndex = value;
- RequireBinding ();
- }
- }
-
- [WebCategoryAttribute ("Styles")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [NotifyParentProperty (true)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public TableItemStyle EditRowStyle {
- get {
- if (editRowStyle == null) {
- editRowStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- editRowStyle.TrackViewState();
- }
- return editRowStyle;
- }
- }
-
- [WebCategoryAttribute ("Styles")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [NotifyParentProperty (true)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public TableItemStyle EmptyDataRowStyle {
- get {
- if (emptyDataRowStyle == null) {
- emptyDataRowStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- emptyDataRowStyle.TrackViewState();
- }
- return emptyDataRowStyle;
- }
- }
-
- [DefaultValue (null)]
- [TemplateContainer (typeof(GridViewRow), BindingDirection.OneWay)]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [Browsable (false)]
- public virtual ITemplate EmptyDataTemplate {
- get { return emptyDataTemplate; }
- set { emptyDataTemplate = value; RequireBinding (); }
- }
-
- [LocalizableAttribute (true)]
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute ("")]
- public virtual string EmptyDataText {
- get {
- object ob = ViewState ["EmptyDataText"];
- if (ob != null) return (string) ob;
- return string.Empty;
- }
- set {
- ViewState ["EmptyDataText"] = value;
- RequireBinding ();
- }
- }
-
- [WebCategoryAttribute ("Behavior")]
- [DefaultValueAttribute (false)]
- public virtual bool EnableSortingAndPagingCallbacks {
- get {
- object ob = ViewState ["EnableSortingAndPagingCallbacks"];
- if (ob != null) return (bool) ob;
- return false;
- }
- set {
- ViewState ["EnableSortingAndPagingCallbacks"] = value;
- RequireBinding ();
- }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public virtual GridViewRow FooterRow {
- get {
- if (table != null) {
- for (int index = table.Rows.Count - 1; index >= 0; index--) {
- GridViewRow row = (GridViewRow) table.Rows [index];
- switch (row.RowType) {
- case DataControlRowType.Separator:
- case DataControlRowType.Pager:
- continue;
- case DataControlRowType.Footer:
- return row;
- default:
- break;
- }
- }
- }
- return null;
- }
- }
-
- [WebCategoryAttribute ("Styles")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [NotifyParentProperty (true)]
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public TableItemStyle FooterStyle {
- get {
- if (footerStyle == null) {
- footerStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- footerStyle.TrackViewState();
- }
- return footerStyle;
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute (GridLines.Both)]
- public virtual GridLines GridLines {
- get {
- if (ControlStyleCreated)
- return ((TableStyle) ControlStyle).GridLines;
- return GridLines.Both;
- }
- set {
- ((TableStyle) ControlStyle).GridLines = value;
- }
- }
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public virtual GridViewRow HeaderRow {
- get {
- if (table != null) {
- for (int index = 0, total = table.Rows.Count; index < total; index++) {
- GridViewRow row = (GridViewRow) table.Rows [index];
- switch (row.RowType) {
- case DataControlRowType.Separator:
- case DataControlRowType.Pager:
- continue;
- case DataControlRowType.Header:
- return row;
- default:
- break;
- }
- }
- }
- return null;
- }
- }
-
- [WebCategoryAttribute ("Styles")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [NotifyParentProperty (true)]
- [DefaultValue (null)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public TableItemStyle HeaderStyle {
- get {
- if (headerStyle == null) {
- headerStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- headerStyle.TrackViewState();
- }
- return headerStyle;
- }
- }
-
- [Category ("Layout")]
- [DefaultValueAttribute (HorizontalAlign.NotSet)]
- public virtual HorizontalAlign HorizontalAlign {
- get {
- if (ControlStyleCreated)
- return ((TableStyle) ControlStyle).HorizontalAlign;
- return HorizontalAlign.NotSet;
- }
- set {
- ((TableStyle) ControlStyle).HorizontalAlign = value;
- }
- }
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual int PageCount {
- get {
- return ViewState.GetInt ("PageCount", 0);
- }
- private set {
- ViewState ["PageCount"] = value;
- }
- }
- [WebCategoryAttribute ("Paging")]
- [BrowsableAttribute (true)]
- [DefaultValueAttribute (0)]
- public virtual int PageIndex {
- get {
- return pageIndex;
- }
- set {
- if (value == pageIndex)
- return;
- pageIndex = value;
- RequireBinding ();
- }
- }
-
- [DefaultValueAttribute (10)]
- [WebCategoryAttribute ("Paging")]
- public virtual int PageSize {
- get {
- object ob = ViewState ["PageSize"];
- if (ob != null) return (int) ob;
- return 10;
- }
- set {
- ViewState ["PageSize"] = value;
- RequireBinding ();
- }
- }
-
- [WebCategoryAttribute ("Paging")]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Content)]
- [NotifyParentPropertyAttribute (true)]
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- public virtual PagerSettings PagerSettings {
- get {
- if (pagerSettings == null) {
- pagerSettings = new PagerSettings (this);
- if (IsTrackingViewState)
- ((IStateManager)pagerSettings).TrackViewState ();
- }
- return pagerSettings;
- }
- }
-
- [WebCategoryAttribute ("Styles")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [NotifyParentProperty (true)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public TableItemStyle PagerStyle {
- get {
- if (pagerStyle == null) {
- pagerStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- pagerStyle.TrackViewState();
- }
- return pagerStyle;
- }
- }
-
-
- [DefaultValue (null)]
- /* DataControlPagerCell isnt specified in the docs */
- //[TemplateContainer (typeof(DataControlPagerCell), BindingDirection.OneWay)]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [Browsable (false)]
- public virtual ITemplate PagerTemplate {
- get { return pagerTemplate; }
- set { pagerTemplate = value; RequireBinding (); }
- }
-
- [DefaultValueAttribute ("")]
- [WebCategoryAttribute ("Accessibility")]
- // [TypeConverterAttribute (typeof(System.Web.UI.Design.DataColumnSelectionConverter)]
- public virtual string RowHeaderColumn {
- get {
- object ob = ViewState ["RowHeaderColumn"];
- if (ob != null) return (string) ob;
- return string.Empty;
- }
- set {
- ViewState ["RowHeaderColumn"] = value;
- RequireBinding ();
- }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public virtual GridViewRowCollection Rows {
- get {
- EnsureChildControls ();
- if (rows == null)
- rows = new GridViewRowCollection (new ArrayList ());
- return rows;
- }
- }
-
- [WebCategoryAttribute ("Styles")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [NotifyParentProperty (true)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public TableItemStyle RowStyle {
- get {
- if (rowStyle == null) {
- rowStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- rowStyle.TrackViewState();
- }
- return rowStyle;
- }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual DataKey SelectedDataKey {
- get {
- if (keys == null)
- throw new InvalidOperationException ("DataKeys");
- if (selectedIndex >= 0 && selectedIndex < DataKeys.Count) {
- return DataKeys [selectedIndex];
- } else
- return null;
- }
- }
-
- [BindableAttribute (true)]
- [DefaultValueAttribute (-1)]
- public virtual int SelectedIndex {
- get {
- return selectedIndex;
- }
- set {
- if (Rows != null && selectedIndex >= 0 && selectedIndex < Rows.Count) {
- int oldIndex = selectedIndex;
- selectedIndex = -1;
- Rows [oldIndex].RowState = GetRowState (oldIndex);
- }
- selectedIndex = value;
- if (Rows != null && selectedIndex >= 0 && selectedIndex < Rows.Count) {
- Rows [selectedIndex].RowState = GetRowState (selectedIndex);
- }
- }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual GridViewRow SelectedRow {
- get {
- if (selectedIndex >= 0 && selectedIndex < Rows.Count) {
- return Rows [selectedIndex];
- } else
- return null;
- }
- }
-
- [WebCategoryAttribute ("Styles")]
- [PersistenceMode (PersistenceMode.InnerProperty)]
- [NotifyParentProperty (true)]
- [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
- public TableItemStyle SelectedRowStyle {
- get {
- if (selectedRowStyle == null) {
- selectedRowStyle = new TableItemStyle ();
- if (IsTrackingViewState)
- selectedRowStyle.TrackViewState();
- }
- return selectedRowStyle;
- }
- }
-
- [BrowsableAttribute (false)]
- public object SelectedValue {
- get {
- if (SelectedDataKey != null)
- return SelectedDataKey.Value;
- else
- return null;
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute (false)]
- public virtual bool ShowFooter {
- get {
- object ob = ViewState ["ShowFooter"];
- if (ob != null) return (bool) ob;
- return false;
- }
- set {
- ViewState ["ShowFooter"] = value;
- RequireBinding ();
- }
- }
-
- [WebCategoryAttribute ("Appearance")]
- [DefaultValueAttribute (true)]
- public virtual bool ShowHeader {
- get {
- object ob = ViewState ["ShowHeader"];
- if (ob != null) return (bool) ob;
- return true;
- }
- set {
- ViewState ["ShowHeader"] = value;
- RequireBinding ();
- }
- }
-
- [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
- [BrowsableAttribute (false)]
- [DefaultValueAttribute (SortDirection.Ascending)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual SortDirection SortDirection {
- get { return sortDirection; }
- private set {
- if (sortDirection == value)
- return;
- sortDirection = value;
- RequireBinding ();
- }
- }
-
- [BrowsableAttribute (false)]
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- public virtual string SortExpression {
- get {
- if (sortExpression == null)
- return String.Empty;
- return sortExpression;
- }
- private set {
- if (sortExpression == value)
- return;
- sortExpression = value;
- RequireBinding ();
- }
- }
-
- [DesignerSerializationVisibilityAttribute (DesignerSerializationVisibility.Hidden)]
- [BrowsableAttribute (false)]
- public virtual GridViewRow TopPagerRow {
- get {
- EnsureDataBound ();
- return topPagerRow;
- }
- }
-
- [WebCategoryAttribute ("Accessibility")]
- [DefaultValueAttribute (true)]
- public virtual bool UseAccessibleHeader {
- get {
- object ob = ViewState ["UseAccessibleHeader"];
- if (ob != null) return (bool) ob;
- return true;
- }
- set {
- ViewState ["UseAccessibleHeader"] = value;
- RequireBinding ();
- }
- }
-
- public virtual bool IsBindableType (Type type)
- {
- return type.IsPrimitive || type == typeof(string) || type == typeof(DateTime) || type == typeof(Guid);
- }
-
- // MSDN: The CreateDataSourceSelectArguments method is a helper method called by
- // the GridView control to create the DataSourceSelectArguments object that
- // contains the arguments passed to the data source. In this implementation,
- // the DataSourceSelectArguments object contains the arguments for paging operations.
- protected override DataSourceSelectArguments CreateDataSourceSelectArguments ()
- {
- DataSourceSelectArguments arg = DataSourceSelectArguments.Empty;
- DataSourceView view= GetData();
- if (AllowPaging && view.CanPage) {
- arg.StartRowIndex = PageIndex * PageSize;
- if (view.CanRetrieveTotalRowCount) {
- arg.RetrieveTotalRowCount = true;
- arg.MaximumRows = PageSize;
- }
- else {
- arg.MaximumRows = -1;
- }
- }
- if (IsBoundUsingDataSourceID && !String.IsNullOrEmpty (sortExpression)) {
- if (sortDirection == SortDirection.Ascending)
- arg.SortExpression = sortExpression;
- else
- arg.SortExpression = sortExpression + " DESC";
- }
-
- return arg;
- }
-
- protected virtual ICollection CreateColumns (PagedDataSource dataSource, bool useDataSource)
- {
- ArrayList fields = new ArrayList ();
-
- if (AutoGenerateEditButton || AutoGenerateDeleteButton || AutoGenerateSelectButton) {
- CommandField field = new CommandField ();
- field.ShowEditButton = AutoGenerateEditButton;
- field.ShowDeleteButton = AutoGenerateDeleteButton;
- field.ShowSelectButton = AutoGenerateSelectButton;
- fields.Add (field);
- }
- fields.AddRange (Columns);
-
- if (AutoGenerateColumns) {
- if (useDataSource)
- autoFieldProperties = CreateAutoFieldProperties (dataSource);
-
- if (autoFieldProperties != null) {
- foreach (AutoGeneratedFieldProperties props in autoFieldProperties)
- fields.Add (CreateAutoGeneratedColumn (props));
- }
- }
-
- return fields;
- }
-
- protected virtual AutoGeneratedField CreateAutoGeneratedColumn (AutoGeneratedFieldProperties fieldProperties)
- {
- return new AutoGeneratedField (fieldProperties);
- }
-
- AutoGeneratedFieldProperties[] CreateAutoFieldProperties (PagedDataSource source)
- {
- if(source == null) return null;
-
- PropertyDescriptorCollection props = source.GetItemProperties (new PropertyDescriptor[0]);
- Type prop_type;
-
- ArrayList retVal = new ArrayList();
-
- if (props == null)
- {
- object fitem = null;
- prop_type = null;
- PropertyInfo prop_item = source.DataSource.GetType().GetProperty("Item",
- BindingFlags.Instance | BindingFlags.Static |
- BindingFlags.Public, null, null,
- new Type[] { typeof(int) }, null);
-
- if (prop_item != null) {
- prop_type = prop_item.PropertyType;
- }
-
- if (prop_type == null || prop_type == typeof(object)) {
- IEnumerator en = source.GetEnumerator();
- if (en.MoveNext())
- fitem = en.Current;
- if (fitem != null)
- prop_type = fitem.GetType();
- }
-
- if (fitem != null && fitem is ICustomTypeDescriptor) {
- props = TypeDescriptor.GetProperties(fitem);
- } else if (prop_type != null) {
- if (IsBindableType (prop_type)) {
- AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
- ((IStateManager)field).TrackViewState();
- field.Name = "Item";
- field.DataField = BoundField.ThisExpression;
- field.Type = prop_type;
- retVal.Add (field);
- } else {
- props = TypeDescriptor.GetProperties (prop_type);
- }
- }
- }
-
- if (props != null && props.Count > 0)
- {
- foreach (PropertyDescriptor current in props) {
- if (IsBindableType (current.PropertyType)) {
- AutoGeneratedFieldProperties field = new AutoGeneratedFieldProperties ();
- ((IStateManager)field).TrackViewState();
- field.Name = current.Name;
- field.DataField = current.Name;
- for (int i = 0; i < DataKeyNames.Length; i++) {
- if (string.Compare (DataKeyNames [i], current.Name, StringComparison.InvariantCultureIgnoreCase) == 0) {
- field.IsReadOnly = true;
- break;
- }
- }
- field.Type = current.PropertyType;
- retVal.Add (field);
- }
- }
- }
- if (retVal.Count > 0)
- return (AutoGeneratedFieldProperties[]) retVal.ToArray (typeof(AutoGeneratedFieldProperties));
- else
- return new AutoGeneratedFieldProperties [0];
- }
-
- protected virtual GridViewRow CreateRow (int rowIndex, int dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState)
- {
- GridViewRow row = new GridViewRow (rowIndex, dataSourceIndex, rowType, rowState);
- return row;
- }
-
- void RequireBinding ()
- {
- if (Initialized) {
- RequiresDataBinding = true;
- }
- }
-
- protected virtual Table CreateChildTable ()
- {
- return new ContainedTable (this);
- }
-
- protected override int CreateChildControls (IEnumerable data, bool dataBinding)
- {
- // clear GridView
- Controls.Clear ();
- table = null;
- rows = null;
-
- if (data == null) {
- return 0;
- }
- PagedDataSource dataSource;
- if (dataBinding) {
- DataSourceView view = GetData ();
- dataSource = new PagedDataSource ();
- dataSource.DataSource = data;
-
- if (AllowPaging) {
- dataSource.AllowPaging = true;
- dataSource.PageSize = PageSize;
- dataSource.CurrentPageIndex = PageIndex;
- if (view.CanPage) {
- dataSource.AllowServerPaging = true;
- if (SelectArguments.RetrieveTotalRowCount)
- dataSource.VirtualCount = SelectArguments.TotalRowCount;
- }
- }
-
- PageCount = dataSource.PageCount;
- }
- else
- {
- dataSource = new PagedDataSource ();
- dataSource.DataSource = data;
- if (AllowPaging) {
- dataSource.AllowPaging = true;
- dataSource.PageSize = PageSize;
- dataSource.CurrentPageIndex = PageIndex;
- }
- }
- if (dataSource.DataSourceCount == 0)
- return 0;
- bool showPager = AllowPaging && (PageCount > 1);
-
- table = CreateChildTable ();
- Controls.Add (table);
-
- ArrayList list = new ArrayList ();
-
- // Creates the set of fields to show
-
- ICollection fieldCollection = CreateColumns (dataSource, dataBinding);
- DataControlField[] fields = new DataControlField [fieldCollection.Count];
- fieldCollection.CopyTo (fields, 0);
- foreach (DataControlField field in fields) {
- field.Initialize (AllowSorting, this);
- if (EnableSortingAndPagingCallbacks)
- field.ValidateSupportsCallback ();
- }
- // Main table creation
-
- if (showPager && PagerSettings.Position == PagerPosition.Top || PagerSettings.Position == PagerPosition.TopAndBottom) {
- topPagerRow = CreatePagerRow (fields.Length, dataSource);
- table.Rows.Add (topPagerRow);
- OnRowCreated (new GridViewRowEventArgs (topPagerRow));
- }
- GridViewRow headerRow = CreateRow (0, 0, DataControlRowType.Header, DataControlRowState.Normal);
- table.Rows.Add (headerRow);
- InitializeRow (headerRow, fields);
- OnRowCreated (new GridViewRowEventArgs (headerRow));
- if (dataBinding) {
- headerRow.DataBind ();
- OnRowDataBound (new GridViewRowEventArgs (headerRow));
- }
-
- foreach (object obj in dataSource) {
- DataControlRowState rstate = GetRowState (list.Count);
- GridViewRow row = CreateRow (list.Count, list.Count, DataControlRowType.DataRow, rstate);
- row.DataItem = obj;
- list.Add (row);
- table.Rows.Add (row);
- InitializeRow (row, fields);
- OnRowCreated (new GridViewRowEventArgs (row));
- if (dataBinding) {
- row.DataBind ();
- OnRowDataBound (new GridViewRowEventArgs (row));
- if (EditIndex == row.RowIndex)
- oldEditValues = new DataKey (GetRowValues (row, true, true));
- DataKeyArrayList.Add (new DataKey (CreateRowDataKey (row), DataKeyNames));
- }
- }
- if (list.Count == 0) {
- GridViewRow emptyRow = CreateEmptyrRow (fields.Length);
- table.Rows.Add (emptyRow);
- OnRowCreated (new GridViewRowEventArgs (emptyRow));
- if (dataBinding) {
- emptyRow.DataBind ();
- OnRowDataBound (new GridViewRowEventArgs (emptyRow));
- }
- }
- GridViewRow footerRow = CreateRow (0, 0, DataControlRowType.Footer, DataControlRowState.Normal);
- table.Rows.Add (footerRow);
- InitializeRow (footerRow, fields);
- OnRowCreated (new GridViewRowEventArgs (footerRow));
- if (dataBinding) {
- footerRow.DataBind ();
- OnRowDataBound (new GridViewRowEventArgs (footerRow));
- }
- if (showPager && PagerSettings.Position == PagerPosition.Bottom || PagerSettings.Position == PagerPosition.TopAndBottom) {
- bottomPagerRow = CreatePagerRow (fields.Length, dataSource);
- table.Rows.Add (bottomPagerRow);
- OnRowCreated (new GridViewRowEventArgs (bottomPagerRow));
- }
- rows = new GridViewRowCollection (list);
- return dataSource.DataSourceCount;
- }
- protected override Style CreateControlStyle ()
- {
- TableStyle style = new TableStyle (ViewState);
- style.GridLines = GridLines.Both;
- style.CellSpacing = 0;
- return style;
- }
-
- DataControlRowState GetRowState (int index)
- {
- DataControlRowState rstate = (index % 2) == 0 ? DataControlRowState.Normal : DataControlRowState.Alternate;
- if (index == SelectedIndex) rstate |= DataControlRowState.Selected;
- if (index == EditIndex) rstate |= DataControlRowState.Edit;
- return rstate;
- }
-
- GridViewRow CreatePagerRow (int fieldCount, PagedDataSource dataSource)
- {
- GridViewRow row = CreateRow (-1, -1, DataControlRowType.Pager, DataControlRowState.Normal);
- InitializePager (row, fieldCount, dataSource);
- return row;
- }
-
- protected virtual void InitializePager (GridViewRow row, int columnSpan, PagedDataSource dataSource)
- {
- TableCell cell = new TableCell ();
- if (columnSpan > 1)
- cell.ColumnSpan = columnSpan;
-
- if (pagerTemplate != null)
- pagerTemplate.InstantiateIn (cell);
- else
- cell.Controls.Add (PagerSettings.CreatePagerControl (dataSource.CurrentPageIndex, dataSource.PageCount));
-
- row.Cells.Add (cell);
- }
-
- GridViewRow CreateEmptyrRow (int fieldCount)
- {
- GridViewRow row = CreateRow (-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
- TableCell cell = new TableCell ();
- cell.ColumnSpan = fieldCount;
-
- if (emptyDataTemplate != null)
- emptyDataTemplate.InstantiateIn (cell);
- else
- cell.Text = EmptyDataText;
-
- row.Cells.Add (cell);
- return row;
- }
-
- protected virtual void InitializeRow (GridViewRow row, DataControlField[] fields)
- {
- DataControlCellType ctype;
- bool accessibleHeader = false;
- switch (row.RowType) {
- case DataControlRowType.Header:
- ctype = DataControlCellType.Header;
- accessibleHeader = UseAccessibleHeader;
- break;
- case DataControlRowType.Footer:
- ctype = DataControlCellType.Footer;
- break;
- default:
- ctype = DataControlCellType.DataCell;
- break;
- }
-
- for (int n=0; n<fields.Length; n++) {
- DataControlField field = fields [n];
- DataControlFieldCell cell;
- if (((field is BoundField) && ((BoundField)field).DataField == RowHeaderColumn) || accessibleHeader)
- cell = new DataControlFieldHeaderCell (field, accessibleHeader ? TableHeaderScope.Column : TableHeaderScope.Row);
- else
- cell = new DataControlFieldCell (field);
- row.Cells.Add (cell);
- field.InitializeCell (cell, ctype, row.RowState, row.RowIndex);
- }
- }
-
- IOrderedDictionary CreateRowDataKey (GridViewRow row)
- {
- if (cachedKeyProperties == null) {
- PropertyDescriptorCollection props = TypeDescriptor.GetProperties (row.DataItem);
- cachedKeyProperties = new PropertyDescriptor [DataKeyNames.Length];
- for (int n=0; n<DataKeyNames.Length; n++) {
- PropertyDescriptor p = props.Find (DataKeyNames [n], true);
- if (p == null)
- throw new InvalidOperationException ("Property '" + DataKeyNames [n] + "' not found in object of type " + row.DataItem.GetType ());
- cachedKeyProperties [n] = p;
- }
- }
-
- OrderedDictionary dic = new OrderedDictionary ();
- foreach (PropertyDescriptor p in cachedKeyProperties)
- dic [p.Name] = p.GetValue (row.DataItem);
- return dic;
- }
-
- IOrderedDictionary GetRowValues (GridViewRow row, bool includeReadOnlyFields, bool includePrimaryKey)
- {
- OrderedDictionary dic = new OrderedDictionary ();
- ExtractRowValues (dic, row, includeReadOnlyFields, includePrimaryKey);
- return dic;
- }
-
- protected virtual void ExtractRowValues (IOrderedDictionary fieldValues, GridViewRow row, bool includeReadOnlyFields, bool includePrimaryKey)
- {
- foreach (TableCell cell in row.Cells) {
- DataControlFieldCell c = cell as DataControlFieldCell;
- if (c != null)
- c.ContainingField.ExtractValuesFromCell (fieldValues, c, row.RowState, includeReadOnlyFields);
- }
- if (!includePrimaryKey && DataKeyNames != null)
- foreach (string key in DataKeyNames)
- fieldValues.Remove (key);
- }
-
- protected override HtmlTextWriterTag TagKey {
- get {
- if (EnableSortingAndPagingCallbacks)
- return HtmlTextWriterTag.Div;
- else
- return HtmlTextWriterTag.Table;
- }
- }
-
- public sealed override void DataBind ()
- {
- DataKeyArrayList.Clear ();
- cachedKeyProperties = null;
- base.DataBind ();
- keys = new DataKeyArray (DataKeyArrayList);
- }
-
- protected internal override void PerformDataBinding (IEnumerable data)
- {
- base.PerformDataBinding (data);
- }
- protected internal virtual void PrepareControlHierarchy ()
- {
- if (table == null)
- return;
-
- table.Caption = Caption;
- table.CaptionAlign = CaptionAlign;
-
- foreach (GridViewRow row in table.Rows) {
- switch (row.RowType) {
- case DataControlRowType.Header:
- if (headerStyle != null && !headerStyle.IsEmpty)
- row.ControlStyle.CopyFrom(headerStyle);
- row.Visible = ShowHeader;
- break;
- case DataControlRowType.Footer:
- if (footerStyle != null && !footerStyle.IsEmpty)
- row.ControlStyle.CopyFrom (footerStyle);
- row.Visible = ShowFooter;
- break;
- case DataControlRowType.Pager:
- if (pagerStyle != null && !pagerStyle.IsEmpty)
- row.ControlStyle.CopyFrom (pagerStyle);
- break;
- case DataControlRowType.EmptyDataRow:
- if (emptyDataRowStyle != null && !emptyDataRowStyle.IsEmpty)
- row.ControlStyle.CopyFrom (emptyDataRowStyle);
- break;
- case DataControlRowType.DataRow:
- if (rowStyle != null && !rowStyle.IsEmpty)
- row.ControlStyle.CopyFrom (rowStyle);
- if ((row.RowState & DataControlRowState.Alternate) != 0 && alternatingRowStyle != null && !alternatingRowStyle.IsEmpty)
- row.ControlStyle.CopyFrom (alternatingRowStyle);
- if ((row.RowState & DataControlRowState.Selected) != 0 && selectedRowStyle != null && !selectedRowStyle.IsEmpty)
- row.ControlStyle.CopyFrom (selectedRowStyle);
- if ((row.RowState & DataControlRowState.Edit) != 0 && editRowStyle != null && !editRowStyle.IsEmpty)
- row.ControlStyle.CopyFrom (editRowStyle);
- break;
- default:
- break;
- }
- foreach (TableCell cell in row.Cells) {
- DataControlFieldCell fcell = cell as DataControlFieldCell;
- if (fcell != null) {
- DataControlField field = fcell.ContainingField;
- switch (row.RowType) {
- case DataControlRowType.Header:
- if (field.HeaderStyleCreated && !field.HeaderStyle.IsEmpty)
- cell.ControlStyle.CopyFrom (field.HeaderStyle);
- break;
- case DataControlRowType.Footer:
- if (field.FooterStyleCreated && !field.FooterStyle.IsEmpty)
- cell.ControlStyle.CopyFrom (field.FooterStyle);
- break;
- default:
- if (field.ControlStyleCreated && !field.ControlStyle.IsEmpty)
- foreach (Control c in cell.Controls) {
- WebControl wc = c as WebControl;
- if (wc != null)
- wc.ControlStyle.MergeWith (field.ControlStyle);
- }
- if (field.ItemStyleCreated && !field.ItemStyle.IsEmpty)
- cell.ControlStyle.CopyFrom (field.ItemStyle);
- break;
- }
- }
- }
- }
- }
-
- protected internal override void OnInit (EventArgs e)
- {
- Page.RegisterRequiresControlState (this);
- base.OnInit (e);
- }
-
- void OnFieldsChanged (object sender, EventArgs args)
- {
- RequireBinding ();
- }
-
- protected override void OnDataPropertyChanged ()
- {
- base.OnDataPropertyChanged ();
- RequireBinding ();
- }
-
- protected override void OnDataSourceViewChanged (object sender, EventArgs e)
- {
- base.OnDataSourceViewChanged (sender, e);
- RequireBinding ();
- }
-
- protected override bool OnBubbleEvent (object source, EventArgs e)
- {
- GridViewCommandEventArgs args = e as GridViewCommandEventArgs;
- if (args != null) {
- bool causesValidation = false;
- IButtonControl button = args.CommandSource as IButtonControl;
- if (button != null && button.CausesValidation) {
- Page.Validate (button.ValidationGroup);
- causesValidation = true;
- }
- OnRowCommand (args);
- string param = args.CommandArgument as string;
- if (param == null || param.Length == 0) {
- GridViewRow row = args.Row;
- if (row != null)
- param = row.RowIndex.ToString();
- }
- ProcessEvent (args.CommandName, param, causesValidation);
- return true;
- }
- return base.OnBubbleEvent (source, e);
- }
-
- void IPostBackEventHandler.RaisePostBackEvent (string eventArgument)
- {
- RaisePostBackEvent (eventArgument);
- }
- // This is prolly obsolete
- protected virtual void RaisePostBackEvent (string eventArgument)
- {
- int i = eventArgument.IndexOf ('$');
- if (i != -1)
- ProcessEvent (eventArgument.Substring (0, i), eventArgument.Substring (i + 1), false);
- else
- ProcessEvent (eventArgument, null, false);
- }
- void ProcessEvent (string eventName, string param, bool causesValidation)
- {
- switch (eventName)
- {
- case DataControlCommands.PageCommandName:
- int newIndex = -1;
- switch (param) {
- case DataControlCommands.FirstPageCommandArgument:
- newIndex = 0;
- break;
- case DataControlCommands.LastPageCommandArgument:
- newIndex = PageCount - 1;
- break;
- case DataControlCommands.NextPageCommandArgument:
- newIndex = PageIndex + 1;
- break;
- case DataControlCommands.PreviousPageCommandArgument:
- newIndex = PageIndex - 1;
- break;
- default:
- int paramIndex = 0;
- int.TryParse (param, out paramIndex);
- newIndex = paramIndex - 1;
- break;
- }
- ShowPage (newIndex);
- break;
-
- case DataControlCommands.FirstPageCommandArgument:
- ShowPage (0);
- break;
- case DataControlCommands.LastPageCommandArgument:
- ShowPage (PageCount - 1);
- break;
-
- case DataControlCommands.NextPageCommandArgument:
- if (PageIndex < PageCount - 1)
- ShowPage (PageIndex + 1);
- break;
- case DataControlCommands.PreviousPageCommandArgument:
- if (PageIndex > 0)
- ShowPage (PageIndex - 1);
- break;
-
- case DataControlCommands.SelectCommandName:
- SelectRow (int.Parse (param));
- break;
-
- case DataControlCommands.EditCommandName:
- EditRow (int.Parse (param));
- break;
-
- case DataControlCommands.UpdateCommandName:
- int editIndex = int.Parse (param);
- UpdateRow (Rows [editIndex], editIndex, causesValidation);
- break;
-
- case DataControlCommands.CancelCommandName:
- CancelEdit ();
- break;
-
- case DataControlCommands.DeleteCommandName:
- DeleteRow (int.Parse (param));
- break;
-
- case DataControlCommands.SortCommandName:
- Sort (param);
- break;
- }
- }
-
- void Sort (string newSortExpression)
- {
- SortDirection newDirection = SortDirection.Ascending;
- if (sortExpression == newSortExpression && sortDirection == SortDirection.Ascending)
- newDirection = SortDirection.Descending;
- Sort (newSortExpression, newDirection);
- }
-
- public virtual void Sort (string newSortExpression, SortDirection newSortDirection)
- {
- GridViewSortEventArgs args = new GridViewSortEventArgs (newSortExpression, newSortDirection);
- OnSorting (args);
- if (args.Cancel) return;
-
- if (IsBoundUsingDataSourceID) {
- EditIndex = -1;
- PageIndex = 0;
- SortExpression = args.SortExpression;
- SortDirection = args.SortDirection;
- }
-
- OnSorted (EventArgs.Empty);
- }
-
- void SelectRow (int index)
- {
- GridViewSelectEventArgs args = new GridViewSelectEventArgs (index);
- OnSelectedIndexChanging (args);
- if (!args.Cancel) {
- SelectedIndex = args.NewSelectedIndex;
- OnSelectedIndexChanged (EventArgs.Empty);
- }
- }
-
- void ShowPage (int newIndex)
- {
- GridViewPageEventArgs args = new GridViewPageEventArgs (newIndex);
- OnPageIndexChanging (args);
-
- if (args.Cancel || !IsBoundUsingDataSourceID)
- return;
-
- EndRowEdit ();
- PageIndex = args.NewPageIndex;
- OnPageIndexChanged (EventArgs.Empty);
- }
-
- void EditRow (int index)
- {
- GridViewEditEventArgs args = new GridViewEditEventArgs (index);
- OnRowEditing (args);
-
- if (args.Cancel || !IsBoundUsingDataSourceID)
- return;
-
- EditIndex = args.NewEditIndex;
- }
-
- void CancelEdit ()
- {
- GridViewCancelEditEventArgs args = new GridViewCancelEditEventArgs (EditIndex);
- OnRowCancelingEdit (args);
-
- if (args.Cancel || !IsBoundUsingDataSourceID)
- return;
- EndRowEdit ();
- }
- [MonoTODO ("Support two-way binding expressions")]
- public virtual void UpdateRow (int rowIndex, bool causesValidation)
- {
- if (rowIndex != EditIndex) throw new NotSupportedException ();
-
- GridViewRow row = Rows [rowIndex];
- UpdateRow (row, rowIndex, causesValidation);
- }
- void UpdateRow (GridViewRow row, int rowIndex, bool causesValidation)
- {
- if (causesValidation && Page != null && !Page.IsValid)
- return;
- currentEditOldValues = OldEditValues.Values;
- currentEditRowKeys = DataKeys [rowIndex].Values;
- currentEditNewValues = GetRowValues (row, false, false);
-
- GridViewUpdateEventArgs args = new GridViewUpdateEventArgs (rowIndex, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
- OnRowUpdating (args);
-
- if (args.Cancel || !IsBoundUsingDataSourceID)
- return;
-
- DataSourceView view = GetData ();
- if (view == null)
- throw new HttpException ("The DataSourceView associated to data bound control was null");
- view.Update (currentEditRowKeys, currentEditNewValues, currentEditOldValues, new DataSourceViewOperationCallback (UpdateCallback));
- }
- bool UpdateCallback (int recordsAffected, Exception exception)
- {
- GridViewUpdatedEventArgs dargs = new GridViewUpdatedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditOldValues, currentEditNewValues);
- OnRowUpdated (dargs);
- if (!dargs.KeepInEditMode)
- EndRowEdit ();
- return dargs.ExceptionHandled;
- }
-
- public virtual void DeleteRow (int rowIndex)
- {
- GridViewRow row = Rows [rowIndex];
- currentEditRowKeys = DataKeys [rowIndex].Values;
- currentEditNewValues = GetRowValues (row, true, true);
-
- GridViewDeleteEventArgs args = new GridViewDeleteEventArgs (rowIndex, currentEditRowKeys, currentEditNewValues);
- OnRowDeleting (args);
- if (args.Cancel || !IsBoundUsingDataSourceID)
- return;
-
- RequireBinding ();
- DataSourceView view = GetData ();
- if (view != null)
- view.Delete (currentEditRowKeys, currentEditNewValues, new DataSourceViewOperationCallback (DeleteCallback));
- else {
- GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (0, null, currentEditRowKeys, currentEditNewValues);
- OnRowDeleted (dargs);
- }
- }
- bool DeleteCallback (int recordsAffected, Exception exception)
- {
- GridViewDeletedEventArgs dargs = new GridViewDeletedEventArgs (recordsAffected, exception, currentEditRowKeys, currentEditNewValues);
- OnRowDeleted (dargs);
- return dargs.ExceptionHandled;
- }
-
- void EndRowEdit ()
- {
- EditIndex = -1;
- oldEditValues = new DataKey (new OrderedDictionary ());
- currentEditRowKeys = null;
- currentEditOldValues = null;
- currentEditNewValues = null;
- }
- protected internal override void LoadControlState (object ob)
- {
- if (ob == null) return;
- object[] state = (object[]) ob;
- base.LoadControlState (state[0]);
- pageIndex = (int) state[1];
- selectedIndex = (int) state[2];
- editIndex = (int) state[3];
- sortExpression = (string) state[4];
- sortDirection = (SortDirection) state[5];
- DataKeyNames = (string []) state [6];
- if (state [7] != null)
- LoadDataKeyArrayState ((object []) state [7]);
- if (state [8] != null)
- ((IStateManager) OldEditValues).LoadViewState (state [8]);
- }
-
- protected internal override object SaveControlState ()
- {
- if (EnableSortingAndPagingCallbacks) {
- Page.ClientScript.RegisterHiddenField (ClientID + "_Page", PageIndex.ToString ());
- Page.ClientScript.RegisterHiddenField (ClientID + "_SortExpression", SortExpression);
- Page.ClientScript.RegisterHiddenField (ClientID + "_SortDirection", ((int)SortDirection).ToString());
- }
- object bstate = base.SaveControlState ();
- return new object [] {
- bstate,
- pageIndex,
- selectedIndex,
- editIndex,
- sortExpression,
- sortDirection,
- DataKeyNames,
- SaveDataKeyArrayState (),
- (oldEditValues == null ? null : ((IStateManager)oldEditValues).SaveViewState ())
- };
- }
- object [] SaveDataKeyArrayState ()
- {
- if (keys == null)
- return null;
- object [] state = new object [keys.Count];
- for (int i = 0; i < keys.Count; i++) {
- state [i] = ((IStateManager) keys [i]).SaveViewState ();
- }
- return state;
- }
- void LoadDataKeyArrayState (object [] state)
- {
- for (int i = 0; i < state.Length; i++) {
- DataKey dataKey = new DataKey (new OrderedDictionary (DataKeyNames.Length), DataKeyNames);
- ((IStateManager) dataKey).LoadViewState (state [i]);
- DataKeyArrayList.Add (dataKey);
- }
- keys = new DataKeyArray (DataKeyArrayList);
- }
- protected override void TrackViewState()
- {
- base.TrackViewState();
- if (columns != null) ((IStateManager)columns).TrackViewState();
- if (pagerSettings != null) ((IStateManager)pagerSettings).TrackViewState();
- if (alternatingRowStyle != null) ((IStateManager)alternatingRowStyle).TrackViewState();
- if (footerStyle != null) ((IStateManager)footerStyle).TrackViewState();
- if (headerStyle != null) ((IStateManager)headerStyle).TrackViewState();
- if (pagerStyle != null) ((IStateManager)pagerStyle).TrackViewState();
- if (rowStyle != null) ((IStateManager)rowStyle).TrackViewState();
- if (selectedRowStyle != null) ((IStateManager)selectedRowStyle).TrackViewState();
- if (editRowStyle != null) ((IStateManager)editRowStyle).TrackViewState();
- if (emptyDataRowStyle != null) ((IStateManager)emptyDataRowStyle).TrackViewState();
- if (keys != null) ((IStateManager)keys).TrackViewState();
- if (autoFieldProperties != null) {
- foreach (IStateManager sm in autoFieldProperties)
- sm.TrackViewState ();
- }
- }
- protected override object SaveViewState()
- {
- object[] states = new object [12];
- states[0] = base.SaveViewState();
- states[1] = (columns == null ? null : ((IStateManager)columns).SaveViewState());
- states[2] = (pagerSettings == null ? null : ((IStateManager)pagerSettings).SaveViewState());
- states[3] = (alternatingRowStyle == null ? null : ((IStateManager)alternatingRowStyle).SaveViewState());
- states[4] = (footerStyle == null ? null : ((IStateManager)footerStyle).SaveViewState());
- states[5] = (headerStyle == null ? null : ((IStateManager)headerStyle).SaveViewState());
- states[6] = (pagerStyle == null ? null : ((IStateManager)pagerStyle).SaveViewState());
- states[7] = (rowStyle == null ? null : ((IStateManager)rowStyle).SaveViewState());
- states[8] = (selectedRowStyle == null ? null : ((IStateManager)selectedRowStyle).SaveViewState());
- states[9] = (editRowStyle == null ? null : ((IStateManager)editRowStyle).SaveViewState());
- states[10] = (emptyDataRowStyle == null ? null : ((IStateManager)emptyDataRowStyle).SaveViewState());
-
- if (autoFieldProperties != null) {
- object[] data = new object [autoFieldProperties.Length];
- bool allNull = true;
- for (int n=0; n<data.Length; n++) {
- data [n] = ((IStateManager)autoFieldProperties [n]).SaveViewState ();
- if (data [n] != null) allNull = false;
- }
- if (!allNull) states [11] = data;
- }
- for (int i = states.Length - 1; i >= 0; i--) {
- if (states [i] != null)
- return states;
- }
- return null;
- }
- protected override void LoadViewState (object savedState)
- {
- if (savedState == null) {
- base.LoadViewState (null);
- return;
- }
- object [] states = (object []) savedState;
-
- if (states[11] != null) {
- object[] data = (object[]) states [11];
- autoFieldProperties = new AutoGeneratedFieldProperties [data.Length];
- for (int n=0; n<data.Length; n++) {
- IStateManager p = new AutoGeneratedFieldProperties ();
- p.TrackViewState ();
- p.LoadViewState (data [n]);
- autoFieldProperties [n] = (AutoGeneratedFieldProperties) p;
- }
- }
- base.LoadViewState (states[0]);
-
- if (states[1] != null) ((IStateManager)Columns).LoadViewState (states[1]);
- if (states[2] != null) ((IStateManager)PagerSettings).LoadViewState (states[2]);
- if (states[3] != null) ((IStateManager)AlternatingRowStyle).LoadViewState (states[3]);
- if (states[4] != null) ((IStateManager)FooterStyle).LoadViewState (states[4]);
- if (states[5] != null) ((IStateManager)HeaderStyle).LoadViewState (states[5]);
- if (states[6] != null) ((IStateManager)PagerStyle).LoadViewState (states[6]);
- if (states[7] != null) ((IStateManager)RowStyle).LoadViewState (states[7]);
- if (states[8] != null) ((IStateManager)SelectedRowStyle).LoadViewState (states[8]);
- if (states[9] != null) ((IStateManager)EditRowStyle).LoadViewState (states[9]);
- if (states[10] != null) ((IStateManager)EmptyDataRowStyle).LoadViewState (states[10]);
- }
-
- void ICallbackEventHandler.RaiseCallbackEvent (string eventArgs)
- {
- RaiseCallbackEvent (eventArgs);
- }
-
- protected virtual void RaiseCallbackEvent (string eventArgs)
- {
- string[] clientData = eventArgs.Split ('|');
- PageIndex = int.Parse (clientData[0]);
- SortExpression = HttpUtility.UrlDecode (clientData [1]);
- SortDirection = (SortDirection) int.Parse (clientData [2]);
-
- RaisePostBackEvent (clientData[3]);
- DataBind ();
- }
-
- string ICallbackEventHandler.GetCallbackResult ()
- {
- return GetCallbackResult ();
- }
- protected virtual string GetCallbackResult ()
- {
- PrepareControlHierarchy ();
-
- StringWriter sw = new StringWriter ();
- sw.Write (PageIndex.ToString () + '|' + SortExpression + '|' + (int) SortDirection + '|');
- HtmlTextWriter writer = new HtmlTextWriter (sw);
- RenderGrid (writer);
- return sw.ToString ();
- }
- string ICallbackContainer.GetCallbackScript (IButtonControl control, string argument)
- {
- return GetCallbackScript (control, argument);
- }
-
- protected virtual string GetCallbackScript (IButtonControl control, string argument)
- {
- if (EnableSortingAndPagingCallbacks)
- return "javascript:GridView_ClientEvent (\"" + ClientID + "\",\"" + control.CommandName + "$" + control.CommandArgument + "\"); return false;";
- else
- return null;
- }
-
- protected override void OnPagePreLoad (object sender, EventArgs e)
- {
- base.OnPagePreLoad (sender, e);
- if (Page.IsPostBack && EnableSortingAndPagingCallbacks) {
- int page;
- if (int.TryParse (Page.Request.Form [ClientID + "_Page"], out page))
- PageIndex = page;
- int dir;
- if (int.TryParse (Page.Request.Form [ClientID + "_SortDirection"], out dir))
- SortDirection = (SortDirection) dir;
- SortExpression = Page.Request.Form [ClientID + "_SortExpression"];
- }
- }
-
- protected internal override void OnPreRender (EventArgs e)
- {
- base.OnPreRender (e);
-
- if (EnableSortingAndPagingCallbacks)
- {
- if (!Page.ClientScript.IsClientScriptIncludeRegistered (typeof(GridView), "GridView.js")) {
- string url = Page.ClientScript.GetWebResourceUrl (typeof(GridView), "GridView.js");
- Page.ClientScript.RegisterClientScriptInclude (typeof(GridView), "GridView.js", url);
- }
-
- string cgrid = ClientID + "_data";
- string script = string.Format ("var {0} = new Object ();\n", cgrid);
- script += string.Format ("{0}.pageIndex = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (PageIndex));
- script += string.Format ("{0}.sortExp = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (SortExpression == null ? "" : SortExpression));
- script += string.Format ("{0}.sortDir = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral ((int) SortDirection));
- script += string.Format ("{0}.uid = {1};\n", cgrid, ClientScriptManager.GetScriptLiteral (UniqueID));
- Page.ClientScript.RegisterStartupScript (typeof(TreeView), this.UniqueID, script, true);
-
- // Make sure the basic script infrastructure is rendered
- Page.ClientScript.GetCallbackEventReference (this, "null", "", "null");
- Page.ClientScript.GetPostBackClientHyperlink (this, "");
- }
- }
- protected internal override void Render (HtmlTextWriter writer)
- {
- PrepareControlHierarchy ();
- if (EnableSortingAndPagingCallbacks)
- writer.AddAttribute (HtmlTextWriterAttribute.Id, ClientID + "_div");
- writer.RenderBeginTag (HtmlTextWriterTag.Div);
- RenderGrid (writer);
- writer.RenderEndTag ();
- }
-
- void RenderGrid (HtmlTextWriter writer)
- {
- if (table == null)
- return;
- table.Render (writer);
- }
- PostBackOptions IPostBackContainer.GetPostBackOptions (IButtonControl control)
- {
- if (control == null)
- throw new ArgumentNullException ("control");
-
- if (control.CausesValidation)
- throw new InvalidOperationException ("A button that causes validation in GridView '" + ID + "' is attempting to use the container GridView as the post back target. The button should either turn off validation or use itself as the post back container.");
-
- PostBackOptions options = new PostBackOptions (this);
- options.Argument = control.CommandName + "$" + control.CommandArgument;
- options.RequiresJavaScriptProtocol = true;
- return options;
- }
- }
- }
- #endif
|