Can I define in datatable hidden columns?

Posted on 2006-04-23
Last Modified: 2011-09-20

I have datatable which is bound to grid.
In addition, this datatable is stored on server side and used to retrieve properties on server side as well.

Now I need to add to select sql 1 additional property:
this property will be used only on business logic side (so no need to render it to client).
But once I addit to sql - it's automatically displayed in grid.

I know how to make the property hidden by GridColumn.Hidden = true, but don't know the answers to the following questaions:

The questions are:
1. Can I define in datatable that column should not be bounded (so that it won't be rendered to client)? - the preferable option since I am chanign business logic and don't want grid be aware of that
2. Can I define in datagrid that column should not be bounded (so that it won't be rendered to client)?
3. Can I define in datatable that column should be hidden (so that it will be rendered to client but won't be dispalyed in grid)?
4. I feel somethign is wrong in my design: I am changing sql, and this requires changing grid as well (unless you find a solution to question 1). What is wrong? What's the right design for such cases?
Question by:netformx
    LVL 15

    Expert Comment

    1. No...

    2. Yes...

    3. No

    4. The correct design in most cases is to setup what is displayed on your grid manually so that when SQL changes the grid does not.

    You are talking about Datagrids so I presume you are using v1.1

    To hide a column without manually setting up the grid's columns you can just do the following

    DataGrid1.Columns[6].visible = false; //Where  is the index of your column.

    I prefer to setup the columns manually, the easiest way it to right click your datagrid and go to [Property Builder]

    Select columns and add [Bound Column]
    Data Field = The field name in the data table and Header text is obvious isn't it ;)

    You can then arrange them easily enough. You can also change the visibility from here as well.

    Let me know if you are using .net 2.0 because it is completely different

    Author Comment

    Actually I am using infragistics grid, and 1.1 and I am setting column manually (at least I was thinking so):

    UltraGridColumn Col1 = UltraWebGrid1.Columns.FromKey(Project.COLUMN_FIELD_NAME);
    Col1.HeaderText = NfxConsts.Header_ProjectName;
    Col1.Width = Unit.Percentage(NfxConsts.ColumnSize_ProjectName);
    UltraGridColumn Col2 = UltraWebGrid1.Columns.FromKey(Project.COLUMN_FIELD_DESCRIPTION);
    Col2.HeaderText = NfxConsts.Header_ProjectDescription;
    Col2.Width = Unit.Percentage(NfxConsts.ColumnSize_ProjectDescription);


    and I bind in UltraWebGrid1_DataBinding event:
    UltraWebGrid1.DataSource = userProjects;

    How can I change the code not to be dependant in sql changes? (I prefer working with code and not Property Builder)
    LVL 15

    Expert Comment

    Hmm... Infragistics... I have not used them much but to manually hide a specific column you can use

    UltraWebGrid1.Bands(0).Columns.FromKey("YourNameofColKeyHere").Hidden = True

    To bind them manually I would presume something along the lines of


    but I don't have infragistics with me to check this...

    Author Comment

    I can check the exact syntex, but I would like to understand the principe. let's assume 1.1 grid:

    what should i do in code to set the columns manually (and not to be dependant on sql changes)?

    I am binding datagring to datatable like this:
    grid.datasource = ...

    Is this the wrong thing to do?
    does it  cause that all colums in datatable are seen (unless put hidden = true)?
    LVL 15

    Accepted Solution

    Generally this would cause all columns to be seen.

    In a normal DataGrid you can either set the columns up in the design view as stated previously.

    or in CodeBehind

    BoundColumn myColumn = new BoundColumn();
    myColumn.DataField = "MySQLField";
    myColumn.HeaderText = "Nice Header";

    DataGrid1.AutoGenerateColumns = false;
    DataGrid1.DataSource = ds;

    So I would setup how ever many columns I need and then whenever my SQL changed as long as the same fields where returned it would work

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Suggested Solutions

    In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now