Baxter
Baxter

Reputation: 5845

Hide Data in asp.net GridView Except When Editing

I am using asp:GridView to display a data table in asp.net, .aspx page. I have a column that contains sensitive information. I would like to display the column with the data grayed out or any other method to hide it so there isn't just a huge visible list of this data column, when the page/gridview loads.
However, when the edit button is clicked on a particular row I would like the sensitive data in the column to be visible and editable.

Any ideas on how to achieve this?

Upvotes: 0

Views: 865

Answers (3)

MrClan
MrClan

Reputation: 6780

you might want to use the rowdatabound event of the gridview to do your job. Find the specific control, (probably textbox) in the current row and then simply set disabled = true. Or you can also set visible=false to hide that particular control from that row. If I;m getting you properly, then this should do your job.

Upvotes: 0

Zo Has
Zo Has

Reputation: 13028

  1. If you don't want to show the data why show that in edit mode ? People can also gaze in edit mode?
  2. You can either open a modal dialog/popup window if you were to hide granular details of your data in gridview.
  3. For now, you can either use DataKeys of gridview & define this column as gridview's dataKey
  4. You can also, set a property on your page set to true or false when the edit button is clicked & switch control visibility like (this would work automatically during databind event)

    private bool isEdit; 
    protected bool IsEditMode
            {
              get {return isEdit;}
             set {isEdit=value;
            }
    

Then in your aspx you will switch desired controls visiblity simply by

Visible='<%# IsEditMode %>'

Upvotes: 0

Steve Wellens
Steve Wellens

Reputation: 20620

Convert the column to a template.

Then you can edit the GridView templates. There are different templates for viewing and editing.

Upvotes: 1

Related Questions