Exclude Fields to prevent users viewing

Posts   
 
    
rell
User
Posts: 25
Joined: 15-Apr-2009
# Posted on: 27-May-2009 06:53:40   

Hi

I am using an asp.net data grid view to view the partial contents of a table. The users are only to see certain fields. I am using the following code to exclude the fields that are not required. But no matter what I try all columns are being displayed. I am obviously missing something but after doing a lot of searching can't see what I am missing. I have tried using ExcludeFieldsList, INcudeFieldsList and ExcludeIncludeFielsList - all with the same results. All columns are displayed. Any help is appreciated.

The code is:

        DeviceTypeCollection dvtColl = new DeviceTypeCollection();

        ExcludeIncludeFieldsList excFields = new ExcludeIncludeFieldsList(true);
        excFields.Add(DeviceTypeFields.CreateDt);
        excFields.Add(DeviceTypeFields.CreateUserId);
        excFields.Add(DeviceTypeFields.LampType);
        excFields.Add(DeviceTypeFields.NomLampRating);
        excFields.Add(DeviceTypeFields.UpdateDt);
        excFields.Add(DeviceTypeFields.UpdateUserId);           

        ISortExpression Sort = new SortExpression();
        Sort.Add(DeviceTypeFields.DevTypeId | SortOperator.Ascending);
        IPredicateExpression Filter = new PredicateExpression();
        Filter.Add(DeviceTypeFields.DevCat == "UMS");
        string compExp = cmbDevType.Text.ToString().ToUpper() + "%";
        Filter.AddWithAnd(DeviceTypeFields.DevTypeId % compExp);

        dvtColl.GetMulti(Filter, 0, Sort, null, null, excFields, 0, 0);
Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 27-May-2009 09:05:04   

And how is the Grid binded? Would you please show the aspx code?

rell
User
Posts: 25
Joined: 15-Apr-2009
# Posted on: 29-May-2009 00:30:23   

Hi Walaa

This app is a windows app, not website, so I am adding the designer code for the form.

        this.dgvSundry = new System.Windows.Forms.DataGridView();

        this.dgvSundry.AllowUserToAddRows = false;
        this.dgvSundry.AllowUserToDeleteRows = false;
        this.dgvSundry.AllowUserToOrderColumns = true;
        this.dgvSundry.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        this.dgvSundry.ContextMenuStrip = this.ctmEdit;
        this.dgvSundry.Location = new System.Drawing.Point(26, 64);
        this.dgvSundry.MultiSelect = false;
        this.dgvSundry.Name = "dgvSundry";
        this.dgvSundry.ReadOnly = true;
        this.dgvSundry.Size = new System.Drawing.Size(637, 269);
        this.dgvSundry.TabIndex = 28;
        this.dgvSundry.Visible = false;


        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(691, 386);
        this.Controls.Add(this.dgvSundry);
        this.Controls.Add(this.btnClose);
        this.Controls.Add(this.label1);
        this.Controls.Add(this.cmbDevType);
        this.Name = "frmSundry";
        this.Text = "Sundry Device Types";
        ((System.ComponentModel.ISupportInitialize)(this.dgvSundry)).EndInit();
        this.ctmEdit.ResumeLayout(false);
        this.ResumeLayout(false);
        this.PerformLayout();

The data binding code is:

        dgvSundry.DataSource = Load_Grid();
        dgvSundry.Visible = true;

Thanks for your assistance with this.

rell
User
Posts: 25
Joined: 15-Apr-2009
# Posted on: 29-May-2009 00:31:25   

Hi WAlaa

Load_Grid() is the code from the first post.;

thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-May-2009 07:02:28   

Ok. You have to add/remove the columns manually (at designer or by code). The include/exclude fields functionality is intended to improve the fetch routine, in case you have fields that wont be used or are too heavy. The fields are there always, but maybe not filled (if they were excluded).

Hope that makes sense to you.

David Elizondo | LLBLGen Support Team
rell
User
Posts: 25
Joined: 15-Apr-2009
# Posted on: 29-May-2009 07:05:25   

Thanks for that.