Autogenerated columns hidden?

Hi all, I've extended a GridView and it now provides all the functionality I will probably ever need (or damn near close) with two exceptions. The first one, I already have a post out there. The second has to do with not including rows from a select in the GridView itself (in other words, I don't want to have to change the query but rather allow the GridView to exlude them). So, I've created a property ExcludeColumns that would be a CSV list of the column indexes (e.g. 1,2,4,6 would exclude the 2nd, 3rd, 5th, and 7th columns). I can simply loop through and set the visibility of the columns I don't want to false.

This is fine when the columns are manually defined. However, when using autogenerated columns, those columns don't appear in the columns collection. Is there any way to get at those autogenerated columns (by the column index) and change their visibility?

I found the following resource but can't figure out how to do it by index with it:

Any ideas? Code in C# or VB or even just textual advice are all equally appreciated.



4/29/2009 3:50:40 PM 3498 articles. 0 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 45


for that you need to implement GridView1_RowCreated. See the following code 


protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
            //Loop through your collection here 
            e.Row.Cells[colIndex].Visible = false;
hope it helps
Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
4/29/2009 6:35:32 PM
I'm already doing that for a property I call HideColumns as that literally hides the column if I include DataRows, HeaderRows, and FooterRows in that loop.  However, I want to hide the column as a whole so that it doesn't appear in the list of parameters when calling insert or update.  Make sense?


4/29/2009 6:57:01 PM

I just ended up changing the property to ExcludeFields and made it a list of the NAMES of each of the fields to exclude. Then I have the following:


protected override void OnRowUpdating (GridViewUpdateEventArgs e)

    // If ExcludeFields isn't empty, we remove those fields before doing our update
    char[] delimiterChars = { ',' };
    string excludeFields = (string) this.ViewState["ExcludeFields"];
    if (!String.IsNullOrEmpty(excludeFields))
        string[] fieldsToExclude = excludeFields.Split(delimiterChars);
        foreach (string col in fieldsToExclude)

Now, it works beautifully!


4/29/2009 9:06:44 PM

Similar Artilces:

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

problems listenening to events on a custom server control from another custom server control
 Hi all,I am having problems listening to events on one of custom server controls(AddBookmark) from another custom server control(BookmarkList). The listener or the BookmarkList control has a property that can be set to the AddBookmark control (string at design but the reference is obtained at run-time). I am able to get a reference to the AddBookmark control and add a listener to it on the BookmarkList control on the OnPrender of BookmarkList. But the problem is that when the events on AddBookmark gets fired, the listener added from the BookmarkList is no longer present and the listene...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer sites and/or SharePoint sites why don't you just create Web Par...

Creating .Net custom server controls and .Net pages programatically
Thanks a lot for reading this and greatly appreciate your inputs I am writing a webinterface that lets users configure options that'll create an interface for them and generete the webpage. So I am having to programattically create custom server controls and .Net page with code behind to support the functionality. Are there APIs in the .NET SDK that let you do this. Any pointers would be greatly helpful Thanks a lot Sathya Controls on the fly? Or Create code on the fly? I think it is the latter so here we go - look at the following namespaces: * System.Reflection.Emit - gen...

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Custom server control display in Studio.NET
I have a custom web server control that I have implemented a control designer using a simple designer: Public Class TPLDesigner    Inherits System.Web.UI.Design.ControlDesigner    Public Overrides Function GetDesignTimeHtml() As String       Dim sw As New StringWriter       Dim tw As New HtmlTextWriter(sw)       Dim cControl As TimePickList = CType(Component, TimePickList)       cControl.RenderControl(tw)     &n...

Building .NET Custom Server Controls and distribution
Can anyone tell me the best practice for distributing custom controls or controls that have been developed from inheriting server controls? I am curious how other companies support a custom library of objects developed by developers within an enterprise. At my company we follow the naming standards put forth by Microsoft: CompanyName.AppName.LayerName Example: Say I developed a Drop Down List that is used to display every year from 2004 to DateTime.Now in ascending order from inheriting the Web Server Control Drop Down List.  After a committee of other developers have tested and app...

how can I persist my columns collection in Custom Server Control?
can somebody tell me please how can I persist my columns collection in Custom Server Control?, i have a custom server control which acts like a multi-column combobox and user can provide the number of columns at the page declarative like this: <cc1:AutoSuggest ID="AutoSuggestMenu1" runat="server" TargetControlID="txt" ><Columns> <cc1:Column HeaderText="Name" /><cc1:Column HeaderText="UserID" /> ............ </Columns></cc1:AutoSuggest>i have a created a seprate class called : ColumnsCollectio...

Custom event for Custom server control
  Hi All, I have a custom server control (Multi selection drop downlist). This control contains AspxEditButton control(which is like textbox with button), check box list control and panel.I have to display all selected values in AspxEditButton at control is leaving that panel. How can i create LostFocus event for panel . Please anyone help meRegards, Anu All I can think of, is that there is a javascript "onblur" you could look into, maybe you could use some AJAX techniques to make that JavaScript event fire a server side ev...

Custom Events in Custom Server Control
 Hi There I've created a custom server control. I have extended it by adding my own event which fires in one of the aggregated control's event handlers. My probelms is that I would like to be able to specify the event handler for the event from the aspx file as a tag attribute.Does anyone know how to link the attribute of a customer server control tag in the aspx file to a custom event in the class source for the control?   I've done this several times with Custom Controls.  All I do is declare the event in the CustomControl's class public...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Custom Server Control - Moving within the VS.Net Designer
Hi, I have created a custom server control that inherits from System.Web.UI.Control. I would like my end users to be able to drag and move the server control in the VS.Net IDE. I presume I have to expose the left/top style properties but can't find anything in the documentation or via google. Any pointers, links or code would be great :) R Hmmm, Inherit from System.Web.UI.WebControls.WebControl or just use the default Create Web Control project in the .Net IDE Can't believe I spent 1 hour looking for this :) Any element can be movable in VS.NET. What it really does is ...

How to render a repeater control in the custom server control?
 How to render a repeater control in the custom server  control because there is a lot of element inside the repeater control? My code is as follows: <div> <asp:Repeater ID="rptFields" runat="server"> <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr> <td><%# Eval("Prompt") %>:</td> <td><asp:PlaceHolder ID="plControl" runat="server" /> <input type="...

Web resources about - Autogenerated columns hidden? -

New attack cracks iPhone autogenerated hotspot passwords in seconds
The top 10 most commonly used words contained in default iPhone hotspot passwords, ordered by relative frequency. Kurtz, et al. If you use ...

Wikipedia:AutoWikiBrowser/User manual - Wikipedia, the free encyclopedia
/u int - /u loads a specified (either by user name or by its number in the list of profiles) user profile, and logs into it. Profile must exist, ...

Software Architecture - Anti Patterns
Anti Patterns Definition An AntiPattern is a literary form that describes a commonly occurring solution to a problem that generates decidedly ...

My Unemployed Life: Have Online Interviews Gone Too Far?
Has the job search process become TOO computerized?

Parallels H-Sphere
Parallels ® H-Sphere Error: Wrong Host The requested host is not found. This may happen due to the following reasons: Domain does not exist. ...

European Tribune - New User
If any of the above concern you, you'll find answers on this short introductory page. If you have other questions, you can consult the New User ...

SEO Mistakes: Autogenerated doorway domains
It seems to me that you have done a good job of clearing spam like this out, however does your algorithm know the difference between doorway ...

Function Reference — Documentation — Puppet Labs
Function ReferenceThis page is autogenerated; any changes will get overwritten (last generated on Wed Feb 19 13:49:38 -0800 2014)There are two ...


Resources last updated: 1/5/2016 7:48:27 PM