• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 718
  • Last Modified:

Can I define in datatable hidden columns?

Hi,

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?
0
netformx
Asked:
netformx
  • 3
  • 2
1 Solution
 
GavinMannionCommented:
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 asp.net 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
0
 
netformxAuthor Commented:
Actually I am using infragistics grid, and asp.net 1.1 and I am setting column manually (at least I was thinking so):

UltraWebGrid1_InitializeLayout
{
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_DataBinding
{
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)
0
 
GavinMannionCommented:
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

UltraWebGrid1.Columns.Add(UltraGridColumn)

but I don't have infragistics with me to check this...
0
 
netformxAuthor Commented:
I can check the exact syntex, but I would like to understand the principe. let's assume asp.net 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 = ...
grid.databind();

Is this the wrong thing to do?
does it  cause that all colums in datatable are seen (unless put hidden = true)?
0
 
GavinMannionCommented:
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.Columns.Add(myColumn);

DataGrid1.AutoGenerateColumns = false;
DataGrid1.DataSource = ds;
DataGrid1.DataBind()

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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now