This is a migrated thread and some comments may be shown as answers.

RadGrid - cannot hide columns without insert failures

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tony
Top achievements
Rank 1
tony asked on 23 May 2012, 07:11 PM
i have a radgrid bound to an entitydatasource. the data has two primary keys which i want to hide. unfortunately attempting to do so creates innumerable nasty side effects. is it possible to hide two columns without losing the ability to set and get values?

i tried first to hide the column but visible=false only hides the column for display. the column bursts forth in all its glory on the insert and update forms of the grid. i don't want users supplying key values.

i set display= false but that didn't hide the column

i set the column to readonly=true but then i could not set the key values. (the grid represents a child of a parent grid - so i am reading the key values of the selected parent row to propagate to the child row. subsequently the insert failed because it had no key values.

when i tried turning the column into a template, (insertedItem["ItemID"].Controls[0] as TextBox) failed to find the column.

is there no way to hide a column and still get and set its values? the real need is to set 2 primary key values (which are foreign keys) before the insert occurs. i thought i could do this in the insertcommand event but events are showing otherwise.

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 25 May 2012, 09:56 PM
Tony,

I believe the best approach is to hide the primary key columns using Visible="false" in the declarative markup. And, then, in the RadGrid PreRender event, you can also add logic similar to the following to hide the columns when in edit mode or insert mode.

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    if (RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted)
    {
 
        RadGrid1.MasterTableView.GetColumn("PrimaryID").Visible = false;
 
        RadGrid1.MasterTableView.GetColumn("SecondaryID").Visible = false;
 
    }
 
}

I hope this helps!
Tags
Grid
Asked by
tony
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or