[{"data":1,"prerenderedAt":1372},["ShallowReactive",2],{"blog:2006:extending-gridview-to-access-generated-columns":3,"blogMore-Development":1358,"comments-extending-gridview-to-access-generated-columns":1371},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"tags":12,"excerpt":17,"body":32,"_type":1349,"_id":1350,"_source":1351,"_file":1352,"_stem":1353,"_extension":1354,"url":1355,"wordCount":1356,"minutes":123,"commentCount":1357},"/blog/2006/extending-gridview-to-access-generated-columns","2006",false,"en","Extending GridView to access generated columns","ASP.NET’s GridView is a useful control and one of it’s best features is it’s ability to generate the columns automatically from the data source given.","2006-09-25T11:27:51+00:00","Development",[13,14,15,16],".NET","ASP.NET","webdev","C#",{"type":18,"children":19},"root",[20,27],{"type":21,"tag":22,"props":23,"children":24},"element","p",{},[25],{"type":26,"value":9},"text",{"type":21,"tag":22,"props":28,"children":29},{},[30],{"type":26,"value":31},"The problem however is that these generated columns are not exposed as part of the Columns collection or even available at all so you can’t hide or manipulate the selected columns.",{"type":18,"children":33,"toc":1345},[34,38,42,47,52,59,860,865,870,876,1325,1330,1339],{"type":21,"tag":22,"props":35,"children":36},{},[37],{"type":26,"value":9},{"type":21,"tag":22,"props":39,"children":40},{},[41],{"type":26,"value":31},{"type":21,"tag":22,"props":43,"children":44},{},[45],{"type":26,"value":46},"One simple scenario might be that you want the first column to be a “View” link to drill down into the row displayed. While you can add the column to the GridView before data binding you can’t actually pull out the information needed from another columns to construct the URL.",{"type":21,"tag":22,"props":48,"children":49},{},[50],{"type":26,"value":51},"By sub-classing GridView you can obtain this functionality with some caveats.",{"type":21,"tag":53,"props":54,"children":56},"h2",{"id":55},"version-1-auto-generated-columns-added-to-the-columns-collection-with-caveats",[57],{"type":26,"value":58},"Version 1: Auto generated columns added to the Columns collection… with caveats.",{"type":21,"tag":60,"props":61,"children":66},"pre",{"className":62,"code":63,"language":64,"meta":65,"style":65},"language-csharp shiki shiki-themes everforest-light dracula","using System;\nusing System.Data;\nusing System.Collections;\nusing System.Web.UI.WebControls;\n\npublic class GridViewEx1 : GridView\n{\n    private DataControlFieldCollection originalColumns;\n\n    public GridViewEx1() : base() {\n    }\n\n    public void RecordColumns() {\n        originalColumns = new DataControlFieldCollection();\n        foreach(DataControlField column in Columns)\n            originalColumns.Add(column as DataControlField);\n    }\n\n    public void ResetColumns() {\n        if (originalColumns == null)\n            RecordColumns();\n        else {\n            Columns.Clear();\n            foreach(DataControlField column in originalColumns)\n                Columns.Add(column as DataControlField);\n        }\n    }\n\n    protected override ICollection CreateColumns(PagedDataSource dataSource, bool useDataSource) {\n        ResetColumns();\n        ICollection generatedColumns = base.CreateColumns(dataSource, useDataSource);\n        foreach(DataControlField column in generatedColumns)\n            if (!originalColumns.Contains(column))\n                Columns.Add(column as DataControlField);\n        return Columns;\n    }\n}\n","csharp","",[67],{"type":21,"tag":68,"props":69,"children":70},"code",{"__ignoreMap":65},[71,95,121,146,189,199,231,240,259,267,297,306,314,337,365,399,433,441,449,470,500,513,527,545,575,604,613,621,629,688,701,738,767,801,829,843,851],{"type":21,"tag":72,"props":73,"children":76},"span",{"class":74,"line":75},"line",1,[77,83,89],{"type":21,"tag":72,"props":78,"children":80},{"style":79},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[81],{"type":26,"value":82},"using",{"type":21,"tag":72,"props":84,"children":86},{"style":85},"--shiki-default:#DF69BA;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[87],{"type":26,"value":88}," System",{"type":21,"tag":72,"props":90,"children":92},{"style":91},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[93],{"type":26,"value":94},";\n",{"type":21,"tag":72,"props":96,"children":98},{"class":74,"line":97},2,[99,103,107,112,117],{"type":21,"tag":72,"props":100,"children":101},{"style":79},[102],{"type":26,"value":82},{"type":21,"tag":72,"props":104,"children":105},{"style":85},[106],{"type":26,"value":88},{"type":21,"tag":72,"props":108,"children":109},{"style":91},[110],{"type":26,"value":111},".",{"type":21,"tag":72,"props":113,"children":114},{"style":85},[115],{"type":26,"value":116},"Data",{"type":21,"tag":72,"props":118,"children":119},{"style":91},[120],{"type":26,"value":94},{"type":21,"tag":72,"props":122,"children":124},{"class":74,"line":123},3,[125,129,133,137,142],{"type":21,"tag":72,"props":126,"children":127},{"style":79},[128],{"type":26,"value":82},{"type":21,"tag":72,"props":130,"children":131},{"style":85},[132],{"type":26,"value":88},{"type":21,"tag":72,"props":134,"children":135},{"style":91},[136],{"type":26,"value":111},{"type":21,"tag":72,"props":138,"children":139},{"style":85},[140],{"type":26,"value":141},"Collections",{"type":21,"tag":72,"props":143,"children":144},{"style":91},[145],{"type":26,"value":94},{"type":21,"tag":72,"props":147,"children":149},{"class":74,"line":148},4,[150,154,158,162,167,171,176,180,185],{"type":21,"tag":72,"props":151,"children":152},{"style":79},[153],{"type":26,"value":82},{"type":21,"tag":72,"props":155,"children":156},{"style":85},[157],{"type":26,"value":88},{"type":21,"tag":72,"props":159,"children":160},{"style":91},[161],{"type":26,"value":111},{"type":21,"tag":72,"props":163,"children":164},{"style":85},[165],{"type":26,"value":166},"Web",{"type":21,"tag":72,"props":168,"children":169},{"style":91},[170],{"type":26,"value":111},{"type":21,"tag":72,"props":172,"children":173},{"style":85},[174],{"type":26,"value":175},"UI",{"type":21,"tag":72,"props":177,"children":178},{"style":91},[179],{"type":26,"value":111},{"type":21,"tag":72,"props":181,"children":182},{"style":85},[183],{"type":26,"value":184},"WebControls",{"type":21,"tag":72,"props":186,"children":187},{"style":91},[188],{"type":26,"value":94},{"type":21,"tag":72,"props":190,"children":192},{"class":74,"line":191},5,[193],{"type":21,"tag":72,"props":194,"children":196},{"emptyLinePlaceholder":195},true,[197],{"type":26,"value":198},"\n",{"type":21,"tag":72,"props":200,"children":202},{"class":74,"line":201},6,[203,209,214,220,225],{"type":21,"tag":72,"props":204,"children":206},{"style":205},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[207],{"type":26,"value":208},"public",{"type":21,"tag":72,"props":210,"children":211},{"style":79},[212],{"type":26,"value":213}," class",{"type":21,"tag":72,"props":215,"children":217},{"style":216},"--shiki-default:#3A94C5;--shiki-dark:#8BE9FD",[218],{"type":26,"value":219}," GridViewEx1",{"type":21,"tag":72,"props":221,"children":222},{"style":91},[223],{"type":26,"value":224}," : ",{"type":21,"tag":72,"props":226,"children":228},{"style":227},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[229],{"type":26,"value":230},"GridView\n",{"type":21,"tag":72,"props":232,"children":234},{"class":74,"line":233},7,[235],{"type":21,"tag":72,"props":236,"children":237},{"style":91},[238],{"type":26,"value":239},"{\n",{"type":21,"tag":72,"props":241,"children":243},{"class":74,"line":242},8,[244,249,254],{"type":21,"tag":72,"props":245,"children":246},{"style":205},[247],{"type":26,"value":248},"    private",{"type":21,"tag":72,"props":250,"children":251},{"style":227},[252],{"type":26,"value":253}," DataControlFieldCollection",{"type":21,"tag":72,"props":255,"children":256},{"style":91},[257],{"type":26,"value":258}," originalColumns;\n",{"type":21,"tag":72,"props":260,"children":262},{"class":74,"line":261},9,[263],{"type":21,"tag":72,"props":264,"children":265},{"emptyLinePlaceholder":195},[266],{"type":26,"value":198},{"type":21,"tag":72,"props":268,"children":270},{"class":74,"line":269},10,[271,276,281,286,292],{"type":21,"tag":72,"props":272,"children":273},{"style":205},[274],{"type":26,"value":275},"    public",{"type":21,"tag":72,"props":277,"children":279},{"style":278},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[280],{"type":26,"value":219},{"type":21,"tag":72,"props":282,"children":283},{"style":91},[284],{"type":26,"value":285},"() : ",{"type":21,"tag":72,"props":287,"children":289},{"style":288},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#BD93F9;--shiki-dark-font-style:italic",[290],{"type":26,"value":291},"base",{"type":21,"tag":72,"props":293,"children":294},{"style":91},[295],{"type":26,"value":296},"() {\n",{"type":21,"tag":72,"props":298,"children":300},{"class":74,"line":299},11,[301],{"type":21,"tag":72,"props":302,"children":303},{"style":91},[304],{"type":26,"value":305},"    }\n",{"type":21,"tag":72,"props":307,"children":309},{"class":74,"line":308},12,[310],{"type":21,"tag":72,"props":311,"children":312},{"emptyLinePlaceholder":195},[313],{"type":26,"value":198},{"type":21,"tag":72,"props":315,"children":317},{"class":74,"line":316},13,[318,322,328,333],{"type":21,"tag":72,"props":319,"children":320},{"style":205},[321],{"type":26,"value":275},{"type":21,"tag":72,"props":323,"children":325},{"style":324},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[326],{"type":26,"value":327}," void",{"type":21,"tag":72,"props":329,"children":330},{"style":278},[331],{"type":26,"value":332}," RecordColumns",{"type":21,"tag":72,"props":334,"children":335},{"style":91},[336],{"type":26,"value":296},{"type":21,"tag":72,"props":338,"children":340},{"class":74,"line":339},14,[341,346,351,356,360],{"type":21,"tag":72,"props":342,"children":343},{"style":91},[344],{"type":26,"value":345},"        originalColumns ",{"type":21,"tag":72,"props":347,"children":348},{"style":205},[349],{"type":26,"value":350},"=",{"type":21,"tag":72,"props":352,"children":353},{"style":79},[354],{"type":26,"value":355}," new",{"type":21,"tag":72,"props":357,"children":358},{"style":227},[359],{"type":26,"value":253},{"type":21,"tag":72,"props":361,"children":362},{"style":91},[363],{"type":26,"value":364},"();\n",{"type":21,"tag":72,"props":366,"children":368},{"class":74,"line":367},15,[369,374,379,384,389,394],{"type":21,"tag":72,"props":370,"children":371},{"style":79},[372],{"type":26,"value":373},"        foreach",{"type":21,"tag":72,"props":375,"children":376},{"style":91},[377],{"type":26,"value":378},"(",{"type":21,"tag":72,"props":380,"children":381},{"style":227},[382],{"type":26,"value":383},"DataControlField",{"type":21,"tag":72,"props":385,"children":386},{"style":91},[387],{"type":26,"value":388}," column ",{"type":21,"tag":72,"props":390,"children":391},{"style":79},[392],{"type":26,"value":393},"in",{"type":21,"tag":72,"props":395,"children":396},{"style":91},[397],{"type":26,"value":398}," Columns)\n",{"type":21,"tag":72,"props":400,"children":402},{"class":74,"line":401},16,[403,408,413,418,423,428],{"type":21,"tag":72,"props":404,"children":405},{"style":91},[406],{"type":26,"value":407},"            originalColumns.",{"type":21,"tag":72,"props":409,"children":410},{"style":278},[411],{"type":26,"value":412},"Add",{"type":21,"tag":72,"props":414,"children":415},{"style":91},[416],{"type":26,"value":417},"(column ",{"type":21,"tag":72,"props":419,"children":420},{"style":79},[421],{"type":26,"value":422},"as",{"type":21,"tag":72,"props":424,"children":425},{"style":227},[426],{"type":26,"value":427}," DataControlField",{"type":21,"tag":72,"props":429,"children":430},{"style":91},[431],{"type":26,"value":432},");\n",{"type":21,"tag":72,"props":434,"children":436},{"class":74,"line":435},17,[437],{"type":21,"tag":72,"props":438,"children":439},{"style":91},[440],{"type":26,"value":305},{"type":21,"tag":72,"props":442,"children":444},{"class":74,"line":443},18,[445],{"type":21,"tag":72,"props":446,"children":447},{"emptyLinePlaceholder":195},[448],{"type":26,"value":198},{"type":21,"tag":72,"props":450,"children":452},{"class":74,"line":451},19,[453,457,461,466],{"type":21,"tag":72,"props":454,"children":455},{"style":205},[456],{"type":26,"value":275},{"type":21,"tag":72,"props":458,"children":459},{"style":324},[460],{"type":26,"value":327},{"type":21,"tag":72,"props":462,"children":463},{"style":278},[464],{"type":26,"value":465}," ResetColumns",{"type":21,"tag":72,"props":467,"children":468},{"style":91},[469],{"type":26,"value":296},{"type":21,"tag":72,"props":471,"children":473},{"class":74,"line":472},20,[474,479,484,489,495],{"type":21,"tag":72,"props":475,"children":476},{"style":79},[477],{"type":26,"value":478},"        if",{"type":21,"tag":72,"props":480,"children":481},{"style":91},[482],{"type":26,"value":483}," (originalColumns ",{"type":21,"tag":72,"props":485,"children":486},{"style":205},[487],{"type":26,"value":488},"==",{"type":21,"tag":72,"props":490,"children":492},{"style":491},"--shiki-default:#DF69BA;--shiki-dark:#BD93F9",[493],{"type":26,"value":494}," null",{"type":21,"tag":72,"props":496,"children":497},{"style":91},[498],{"type":26,"value":499},")\n",{"type":21,"tag":72,"props":501,"children":503},{"class":74,"line":502},21,[504,509],{"type":21,"tag":72,"props":505,"children":506},{"style":278},[507],{"type":26,"value":508},"            RecordColumns",{"type":21,"tag":72,"props":510,"children":511},{"style":91},[512],{"type":26,"value":364},{"type":21,"tag":72,"props":514,"children":516},{"class":74,"line":515},22,[517,522],{"type":21,"tag":72,"props":518,"children":519},{"style":79},[520],{"type":26,"value":521},"        else",{"type":21,"tag":72,"props":523,"children":524},{"style":91},[525],{"type":26,"value":526}," {\n",{"type":21,"tag":72,"props":528,"children":530},{"class":74,"line":529},23,[531,536,541],{"type":21,"tag":72,"props":532,"children":533},{"style":91},[534],{"type":26,"value":535},"            Columns.",{"type":21,"tag":72,"props":537,"children":538},{"style":278},[539],{"type":26,"value":540},"Clear",{"type":21,"tag":72,"props":542,"children":543},{"style":91},[544],{"type":26,"value":364},{"type":21,"tag":72,"props":546,"children":548},{"class":74,"line":547},24,[549,554,558,562,566,570],{"type":21,"tag":72,"props":550,"children":551},{"style":79},[552],{"type":26,"value":553},"            foreach",{"type":21,"tag":72,"props":555,"children":556},{"style":91},[557],{"type":26,"value":378},{"type":21,"tag":72,"props":559,"children":560},{"style":227},[561],{"type":26,"value":383},{"type":21,"tag":72,"props":563,"children":564},{"style":91},[565],{"type":26,"value":388},{"type":21,"tag":72,"props":567,"children":568},{"style":79},[569],{"type":26,"value":393},{"type":21,"tag":72,"props":571,"children":572},{"style":91},[573],{"type":26,"value":574}," originalColumns)\n",{"type":21,"tag":72,"props":576,"children":578},{"class":74,"line":577},25,[579,584,588,592,596,600],{"type":21,"tag":72,"props":580,"children":581},{"style":91},[582],{"type":26,"value":583},"                Columns.",{"type":21,"tag":72,"props":585,"children":586},{"style":278},[587],{"type":26,"value":412},{"type":21,"tag":72,"props":589,"children":590},{"style":91},[591],{"type":26,"value":417},{"type":21,"tag":72,"props":593,"children":594},{"style":79},[595],{"type":26,"value":422},{"type":21,"tag":72,"props":597,"children":598},{"style":227},[599],{"type":26,"value":427},{"type":21,"tag":72,"props":601,"children":602},{"style":91},[603],{"type":26,"value":432},{"type":21,"tag":72,"props":605,"children":607},{"class":74,"line":606},26,[608],{"type":21,"tag":72,"props":609,"children":610},{"style":91},[611],{"type":26,"value":612},"        }\n",{"type":21,"tag":72,"props":614,"children":616},{"class":74,"line":615},27,[617],{"type":21,"tag":72,"props":618,"children":619},{"style":91},[620],{"type":26,"value":305},{"type":21,"tag":72,"props":622,"children":624},{"class":74,"line":623},28,[625],{"type":21,"tag":72,"props":626,"children":627},{"emptyLinePlaceholder":195},[628],{"type":26,"value":198},{"type":21,"tag":72,"props":630,"children":632},{"class":74,"line":631},29,[633,638,643,648,653,657,662,668,673,678,683],{"type":21,"tag":72,"props":634,"children":635},{"style":205},[636],{"type":26,"value":637},"    protected",{"type":21,"tag":72,"props":639,"children":640},{"style":205},[641],{"type":26,"value":642}," override",{"type":21,"tag":72,"props":644,"children":645},{"style":227},[646],{"type":26,"value":647}," ICollection",{"type":21,"tag":72,"props":649,"children":650},{"style":278},[651],{"type":26,"value":652}," CreateColumns",{"type":21,"tag":72,"props":654,"children":655},{"style":91},[656],{"type":26,"value":378},{"type":21,"tag":72,"props":658,"children":659},{"style":227},[660],{"type":26,"value":661},"PagedDataSource",{"type":21,"tag":72,"props":663,"children":665},{"style":664},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic",[666],{"type":26,"value":667}," dataSource",{"type":21,"tag":72,"props":669,"children":670},{"style":91},[671],{"type":26,"value":672},", ",{"type":21,"tag":72,"props":674,"children":675},{"style":324},[676],{"type":26,"value":677},"bool",{"type":21,"tag":72,"props":679,"children":680},{"style":664},[681],{"type":26,"value":682}," useDataSource",{"type":21,"tag":72,"props":684,"children":685},{"style":91},[686],{"type":26,"value":687},") {\n",{"type":21,"tag":72,"props":689,"children":691},{"class":74,"line":690},30,[692,697],{"type":21,"tag":72,"props":693,"children":694},{"style":278},[695],{"type":26,"value":696},"        ResetColumns",{"type":21,"tag":72,"props":698,"children":699},{"style":91},[700],{"type":26,"value":364},{"type":21,"tag":72,"props":702,"children":704},{"class":74,"line":703},31,[705,710,715,719,724,728,733],{"type":21,"tag":72,"props":706,"children":707},{"style":227},[708],{"type":26,"value":709},"        ICollection",{"type":21,"tag":72,"props":711,"children":712},{"style":91},[713],{"type":26,"value":714}," generatedColumns ",{"type":21,"tag":72,"props":716,"children":717},{"style":205},[718],{"type":26,"value":350},{"type":21,"tag":72,"props":720,"children":721},{"style":288},[722],{"type":26,"value":723}," base",{"type":21,"tag":72,"props":725,"children":726},{"style":91},[727],{"type":26,"value":111},{"type":21,"tag":72,"props":729,"children":730},{"style":278},[731],{"type":26,"value":732},"CreateColumns",{"type":21,"tag":72,"props":734,"children":735},{"style":91},[736],{"type":26,"value":737},"(dataSource, useDataSource);\n",{"type":21,"tag":72,"props":739,"children":741},{"class":74,"line":740},32,[742,746,750,754,758,762],{"type":21,"tag":72,"props":743,"children":744},{"style":79},[745],{"type":26,"value":373},{"type":21,"tag":72,"props":747,"children":748},{"style":91},[749],{"type":26,"value":378},{"type":21,"tag":72,"props":751,"children":752},{"style":227},[753],{"type":26,"value":383},{"type":21,"tag":72,"props":755,"children":756},{"style":91},[757],{"type":26,"value":388},{"type":21,"tag":72,"props":759,"children":760},{"style":79},[761],{"type":26,"value":393},{"type":21,"tag":72,"props":763,"children":764},{"style":91},[765],{"type":26,"value":766}," generatedColumns)\n",{"type":21,"tag":72,"props":768,"children":770},{"class":74,"line":769},33,[771,776,781,786,791,796],{"type":21,"tag":72,"props":772,"children":773},{"style":79},[774],{"type":26,"value":775},"            if",{"type":21,"tag":72,"props":777,"children":778},{"style":91},[779],{"type":26,"value":780}," (",{"type":21,"tag":72,"props":782,"children":783},{"style":205},[784],{"type":26,"value":785},"!",{"type":21,"tag":72,"props":787,"children":788},{"style":91},[789],{"type":26,"value":790},"originalColumns.",{"type":21,"tag":72,"props":792,"children":793},{"style":278},[794],{"type":26,"value":795},"Contains",{"type":21,"tag":72,"props":797,"children":798},{"style":91},[799],{"type":26,"value":800},"(column))\n",{"type":21,"tag":72,"props":802,"children":804},{"class":74,"line":803},34,[805,809,813,817,821,825],{"type":21,"tag":72,"props":806,"children":807},{"style":91},[808],{"type":26,"value":583},{"type":21,"tag":72,"props":810,"children":811},{"style":278},[812],{"type":26,"value":412},{"type":21,"tag":72,"props":814,"children":815},{"style":91},[816],{"type":26,"value":417},{"type":21,"tag":72,"props":818,"children":819},{"style":79},[820],{"type":26,"value":422},{"type":21,"tag":72,"props":822,"children":823},{"style":227},[824],{"type":26,"value":427},{"type":21,"tag":72,"props":826,"children":827},{"style":91},[828],{"type":26,"value":432},{"type":21,"tag":72,"props":830,"children":832},{"class":74,"line":831},35,[833,838],{"type":21,"tag":72,"props":834,"children":835},{"style":79},[836],{"type":26,"value":837},"        return",{"type":21,"tag":72,"props":839,"children":840},{"style":91},[841],{"type":26,"value":842}," Columns;\n",{"type":21,"tag":72,"props":844,"children":846},{"class":74,"line":845},36,[847],{"type":21,"tag":72,"props":848,"children":849},{"style":91},[850],{"type":26,"value":305},{"type":21,"tag":72,"props":852,"children":854},{"class":74,"line":853},37,[855],{"type":21,"tag":72,"props":856,"children":857},{"style":91},[858],{"type":26,"value":859},"}\n",{"type":21,"tag":22,"props":861,"children":862},{},[863],{"type":26,"value":864},"This version provides some compatibility with existing code/expectations in that the auto-generated columns are part of the Columns collection after the DataBind.",{"type":21,"tag":22,"props":866,"children":867},{},[868],{"type":26,"value":869},"Should you call DataBind again however as well as wiping out the changes to the generated columns (they are, after all re-generated) any additional columns added to the collection after the first DataBind will also be lost as it does not track which are added by the programmer and which automatically.",{"type":21,"tag":53,"props":871,"children":873},{"id":872},"version-2-all-bound-columns-exposed-as-boundcolumns-user-ones-as-columns",[874],{"type":26,"value":875},"Version 2: All bound columns exposed as BoundColumns, user ones as Columns.",{"type":21,"tag":60,"props":877,"children":879},{"className":62,"code":878,"language":64,"meta":65,"style":65},"using System;\nusing System.Data;\nusing System.Collections;\nusing System.Web.UI.WebControls;\n\npublic class GridViewEx2 : GridView\n{\n    private DataControlFieldCollection boundColumns = new DataControlFieldCollection();\n\n    public GridViewEx2() : base() {\n    }\n\n    public DataControlFieldCollection BoundColumns {\n        get { return boundColumns; }\n    }\n\n    protected override ICollection CreateColumns(PagedDataSource dataSource, bool useDataSource) {\n        ICollection generatedColumns = base.CreateColumns(dataSource, useDataSource);\n        BoundColumns.Clear();\n        foreach (DataControlField column in generatedColumns)\n            BoundColumns.Add(column as DataControlField);\n        return BoundColumns;\n    }\n}\n",[880],{"type":21,"tag":68,"props":881,"children":882},{"__ignoreMap":65},[883,898,921,944,983,990,1014,1021,1053,1060,1083,1090,1097,1113,1136,1143,1150,1197,1228,1244,1271,1299,1311,1318],{"type":21,"tag":72,"props":884,"children":885},{"class":74,"line":75},[886,890,894],{"type":21,"tag":72,"props":887,"children":888},{"style":79},[889],{"type":26,"value":82},{"type":21,"tag":72,"props":891,"children":892},{"style":85},[893],{"type":26,"value":88},{"type":21,"tag":72,"props":895,"children":896},{"style":91},[897],{"type":26,"value":94},{"type":21,"tag":72,"props":899,"children":900},{"class":74,"line":97},[901,905,909,913,917],{"type":21,"tag":72,"props":902,"children":903},{"style":79},[904],{"type":26,"value":82},{"type":21,"tag":72,"props":906,"children":907},{"style":85},[908],{"type":26,"value":88},{"type":21,"tag":72,"props":910,"children":911},{"style":91},[912],{"type":26,"value":111},{"type":21,"tag":72,"props":914,"children":915},{"style":85},[916],{"type":26,"value":116},{"type":21,"tag":72,"props":918,"children":919},{"style":91},[920],{"type":26,"value":94},{"type":21,"tag":72,"props":922,"children":923},{"class":74,"line":123},[924,928,932,936,940],{"type":21,"tag":72,"props":925,"children":926},{"style":79},[927],{"type":26,"value":82},{"type":21,"tag":72,"props":929,"children":930},{"style":85},[931],{"type":26,"value":88},{"type":21,"tag":72,"props":933,"children":934},{"style":91},[935],{"type":26,"value":111},{"type":21,"tag":72,"props":937,"children":938},{"style":85},[939],{"type":26,"value":141},{"type":21,"tag":72,"props":941,"children":942},{"style":91},[943],{"type":26,"value":94},{"type":21,"tag":72,"props":945,"children":946},{"class":74,"line":148},[947,951,955,959,963,967,971,975,979],{"type":21,"tag":72,"props":948,"children":949},{"style":79},[950],{"type":26,"value":82},{"type":21,"tag":72,"props":952,"children":953},{"style":85},[954],{"type":26,"value":88},{"type":21,"tag":72,"props":956,"children":957},{"style":91},[958],{"type":26,"value":111},{"type":21,"tag":72,"props":960,"children":961},{"style":85},[962],{"type":26,"value":166},{"type":21,"tag":72,"props":964,"children":965},{"style":91},[966],{"type":26,"value":111},{"type":21,"tag":72,"props":968,"children":969},{"style":85},[970],{"type":26,"value":175},{"type":21,"tag":72,"props":972,"children":973},{"style":91},[974],{"type":26,"value":111},{"type":21,"tag":72,"props":976,"children":977},{"style":85},[978],{"type":26,"value":184},{"type":21,"tag":72,"props":980,"children":981},{"style":91},[982],{"type":26,"value":94},{"type":21,"tag":72,"props":984,"children":985},{"class":74,"line":191},[986],{"type":21,"tag":72,"props":987,"children":988},{"emptyLinePlaceholder":195},[989],{"type":26,"value":198},{"type":21,"tag":72,"props":991,"children":992},{"class":74,"line":201},[993,997,1001,1006,1010],{"type":21,"tag":72,"props":994,"children":995},{"style":205},[996],{"type":26,"value":208},{"type":21,"tag":72,"props":998,"children":999},{"style":79},[1000],{"type":26,"value":213},{"type":21,"tag":72,"props":1002,"children":1003},{"style":216},[1004],{"type":26,"value":1005}," GridViewEx2",{"type":21,"tag":72,"props":1007,"children":1008},{"style":91},[1009],{"type":26,"value":224},{"type":21,"tag":72,"props":1011,"children":1012},{"style":227},[1013],{"type":26,"value":230},{"type":21,"tag":72,"props":1015,"children":1016},{"class":74,"line":233},[1017],{"type":21,"tag":72,"props":1018,"children":1019},{"style":91},[1020],{"type":26,"value":239},{"type":21,"tag":72,"props":1022,"children":1023},{"class":74,"line":242},[1024,1028,1032,1037,1041,1045,1049],{"type":21,"tag":72,"props":1025,"children":1026},{"style":205},[1027],{"type":26,"value":248},{"type":21,"tag":72,"props":1029,"children":1030},{"style":227},[1031],{"type":26,"value":253},{"type":21,"tag":72,"props":1033,"children":1034},{"style":91},[1035],{"type":26,"value":1036}," boundColumns ",{"type":21,"tag":72,"props":1038,"children":1039},{"style":205},[1040],{"type":26,"value":350},{"type":21,"tag":72,"props":1042,"children":1043},{"style":79},[1044],{"type":26,"value":355},{"type":21,"tag":72,"props":1046,"children":1047},{"style":227},[1048],{"type":26,"value":253},{"type":21,"tag":72,"props":1050,"children":1051},{"style":91},[1052],{"type":26,"value":364},{"type":21,"tag":72,"props":1054,"children":1055},{"class":74,"line":261},[1056],{"type":21,"tag":72,"props":1057,"children":1058},{"emptyLinePlaceholder":195},[1059],{"type":26,"value":198},{"type":21,"tag":72,"props":1061,"children":1062},{"class":74,"line":269},[1063,1067,1071,1075,1079],{"type":21,"tag":72,"props":1064,"children":1065},{"style":205},[1066],{"type":26,"value":275},{"type":21,"tag":72,"props":1068,"children":1069},{"style":278},[1070],{"type":26,"value":1005},{"type":21,"tag":72,"props":1072,"children":1073},{"style":91},[1074],{"type":26,"value":285},{"type":21,"tag":72,"props":1076,"children":1077},{"style":288},[1078],{"type":26,"value":291},{"type":21,"tag":72,"props":1080,"children":1081},{"style":91},[1082],{"type":26,"value":296},{"type":21,"tag":72,"props":1084,"children":1085},{"class":74,"line":299},[1086],{"type":21,"tag":72,"props":1087,"children":1088},{"style":91},[1089],{"type":26,"value":305},{"type":21,"tag":72,"props":1091,"children":1092},{"class":74,"line":308},[1093],{"type":21,"tag":72,"props":1094,"children":1095},{"emptyLinePlaceholder":195},[1096],{"type":26,"value":198},{"type":21,"tag":72,"props":1098,"children":1099},{"class":74,"line":316},[1100,1104,1108],{"type":21,"tag":72,"props":1101,"children":1102},{"style":205},[1103],{"type":26,"value":275},{"type":21,"tag":72,"props":1105,"children":1106},{"style":227},[1107],{"type":26,"value":253},{"type":21,"tag":72,"props":1109,"children":1110},{"style":91},[1111],{"type":26,"value":1112}," BoundColumns {\n",{"type":21,"tag":72,"props":1114,"children":1115},{"class":74,"line":339},[1116,1121,1126,1131],{"type":21,"tag":72,"props":1117,"children":1118},{"style":324},[1119],{"type":26,"value":1120},"        get",{"type":21,"tag":72,"props":1122,"children":1123},{"style":91},[1124],{"type":26,"value":1125}," { ",{"type":21,"tag":72,"props":1127,"children":1128},{"style":79},[1129],{"type":26,"value":1130},"return",{"type":21,"tag":72,"props":1132,"children":1133},{"style":91},[1134],{"type":26,"value":1135}," boundColumns; }\n",{"type":21,"tag":72,"props":1137,"children":1138},{"class":74,"line":367},[1139],{"type":21,"tag":72,"props":1140,"children":1141},{"style":91},[1142],{"type":26,"value":305},{"type":21,"tag":72,"props":1144,"children":1145},{"class":74,"line":401},[1146],{"type":21,"tag":72,"props":1147,"children":1148},{"emptyLinePlaceholder":195},[1149],{"type":26,"value":198},{"type":21,"tag":72,"props":1151,"children":1152},{"class":74,"line":435},[1153,1157,1161,1165,1169,1173,1177,1181,1185,1189,1193],{"type":21,"tag":72,"props":1154,"children":1155},{"style":205},[1156],{"type":26,"value":637},{"type":21,"tag":72,"props":1158,"children":1159},{"style":205},[1160],{"type":26,"value":642},{"type":21,"tag":72,"props":1162,"children":1163},{"style":227},[1164],{"type":26,"value":647},{"type":21,"tag":72,"props":1166,"children":1167},{"style":278},[1168],{"type":26,"value":652},{"type":21,"tag":72,"props":1170,"children":1171},{"style":91},[1172],{"type":26,"value":378},{"type":21,"tag":72,"props":1174,"children":1175},{"style":227},[1176],{"type":26,"value":661},{"type":21,"tag":72,"props":1178,"children":1179},{"style":664},[1180],{"type":26,"value":667},{"type":21,"tag":72,"props":1182,"children":1183},{"style":91},[1184],{"type":26,"value":672},{"type":21,"tag":72,"props":1186,"children":1187},{"style":324},[1188],{"type":26,"value":677},{"type":21,"tag":72,"props":1190,"children":1191},{"style":664},[1192],{"type":26,"value":682},{"type":21,"tag":72,"props":1194,"children":1195},{"style":91},[1196],{"type":26,"value":687},{"type":21,"tag":72,"props":1198,"children":1199},{"class":74,"line":443},[1200,1204,1208,1212,1216,1220,1224],{"type":21,"tag":72,"props":1201,"children":1202},{"style":227},[1203],{"type":26,"value":709},{"type":21,"tag":72,"props":1205,"children":1206},{"style":91},[1207],{"type":26,"value":714},{"type":21,"tag":72,"props":1209,"children":1210},{"style":205},[1211],{"type":26,"value":350},{"type":21,"tag":72,"props":1213,"children":1214},{"style":288},[1215],{"type":26,"value":723},{"type":21,"tag":72,"props":1217,"children":1218},{"style":91},[1219],{"type":26,"value":111},{"type":21,"tag":72,"props":1221,"children":1222},{"style":278},[1223],{"type":26,"value":732},{"type":21,"tag":72,"props":1225,"children":1226},{"style":91},[1227],{"type":26,"value":737},{"type":21,"tag":72,"props":1229,"children":1230},{"class":74,"line":451},[1231,1236,1240],{"type":21,"tag":72,"props":1232,"children":1233},{"style":91},[1234],{"type":26,"value":1235},"        BoundColumns.",{"type":21,"tag":72,"props":1237,"children":1238},{"style":278},[1239],{"type":26,"value":540},{"type":21,"tag":72,"props":1241,"children":1242},{"style":91},[1243],{"type":26,"value":364},{"type":21,"tag":72,"props":1245,"children":1246},{"class":74,"line":472},[1247,1251,1255,1259,1263,1267],{"type":21,"tag":72,"props":1248,"children":1249},{"style":79},[1250],{"type":26,"value":373},{"type":21,"tag":72,"props":1252,"children":1253},{"style":91},[1254],{"type":26,"value":780},{"type":21,"tag":72,"props":1256,"children":1257},{"style":227},[1258],{"type":26,"value":383},{"type":21,"tag":72,"props":1260,"children":1261},{"style":91},[1262],{"type":26,"value":388},{"type":21,"tag":72,"props":1264,"children":1265},{"style":79},[1266],{"type":26,"value":393},{"type":21,"tag":72,"props":1268,"children":1269},{"style":91},[1270],{"type":26,"value":766},{"type":21,"tag":72,"props":1272,"children":1273},{"class":74,"line":502},[1274,1279,1283,1287,1291,1295],{"type":21,"tag":72,"props":1275,"children":1276},{"style":91},[1277],{"type":26,"value":1278},"            BoundColumns.",{"type":21,"tag":72,"props":1280,"children":1281},{"style":278},[1282],{"type":26,"value":412},{"type":21,"tag":72,"props":1284,"children":1285},{"style":91},[1286],{"type":26,"value":417},{"type":21,"tag":72,"props":1288,"children":1289},{"style":79},[1290],{"type":26,"value":422},{"type":21,"tag":72,"props":1292,"children":1293},{"style":227},[1294],{"type":26,"value":427},{"type":21,"tag":72,"props":1296,"children":1297},{"style":91},[1298],{"type":26,"value":432},{"type":21,"tag":72,"props":1300,"children":1301},{"class":74,"line":515},[1302,1306],{"type":21,"tag":72,"props":1303,"children":1304},{"style":79},[1305],{"type":26,"value":837},{"type":21,"tag":72,"props":1307,"children":1308},{"style":91},[1309],{"type":26,"value":1310}," BoundColumns;\n",{"type":21,"tag":72,"props":1312,"children":1313},{"class":74,"line":529},[1314],{"type":21,"tag":72,"props":1315,"children":1316},{"style":91},[1317],{"type":26,"value":305},{"type":21,"tag":72,"props":1319,"children":1320},{"class":74,"line":547},[1321],{"type":21,"tag":72,"props":1322,"children":1323},{"style":91},[1324],{"type":26,"value":859},{"type":21,"tag":22,"props":1326,"children":1327},{},[1328],{"type":26,"value":1329},"After the DataBind you will have full access to the generated columns as part of the BoundColumns collection.",{"type":21,"tag":22,"props":1331,"children":1332},{},[1333],{"type":21,"tag":1334,"props":1335,"children":1336},"em",{},[1337],{"type":26,"value":1338},"[)amien",{"type":21,"tag":1340,"props":1341,"children":1342},"style",{},[1343],{"type":26,"value":1344},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":65,"searchDepth":97,"depth":97,"links":1346},[1347,1348],{"id":55,"depth":97,"text":58},{"id":872,"depth":97,"text":875},"markdown","content:blog:2006:extending-gridview-to-access-generated-columns.md","content","blog/2006/extending-gridview-to-access-generated-columns.md","blog/2006/extending-gridview-to-access-generated-columns","md","/blog/2006/extending-gridview-to-access-generated-columns/",506,0,[1359,1363,1367],{"title":1360,"date":1361,"url":1362},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":1364,"date":1365,"url":1366},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/mongodb-explicit-transactions/",{"title":1368,"date":1369,"url":1370},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",[],1779264595915]