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

Hiding Labels in Insert mode for read only fields

8 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 26 Aug 2015, 01:28 PM

This might be a little hard to explain but i'm going to do my best because i'm stuck.

I've programatically created an EditTemplate Column using an IBindableTemplate.

The call looks like:

GridTemplateColumn col = new GridTemplateColumn();
col.ItemTemplate = new ItemLabel(column);
col.EditItemTemplate = new EditRadNumTextbox(grid, column);
 

I could create an insert template but the problem im having is even if i do have an insert template I'm not sure how to find and hide the labels so i end up with a labels in the left column with hidden controls in the right column in the edit form.

 

How do I find the label in edit/insert mode with in an IBindableTemplate class?

it appears i have two places i can look for it in 

 public void InstantiateIn(Control container)

or in the control databinding, but in insertmode there's nothing to bind to so i assume i should be able to find the label in InstantiateIn?

Or is there a way to set GridTemplateColumn to not show the label ion insert?

 

Any help would be much appreciated.

 

 

 ​

8 Answers, 1 is accepted

Sort by
0
Phil
Top achievements
Rank 1
answered on 26 Aug 2015, 04:39 PM

Never mind, I figured it out.

Below is my solution, "column" is my data object that contains all the properties of our grid. I check when i want to hide on insert mode and set always hidden when its not supposed to be shown.

if (column.SCSFC_DoNotDisplay || column.SCSFC_Hide_In_Edit_Mode || column.SCSFC_ReadOnly)
{
      col.InsertVisiblityMode = GridColumnVisibilityMode.AlwaysHidden;
}​

0
Eyup
Telerik team
answered on 31 Aug 2015, 10:05 AM
Hello Phil,

If you want to achieve this depending on a condition per individual record, you can determine whether the item is in edit or insert form:
http://www.telerik.com/help/aspnet-ajax/grid-distinguish-edit-insert-mode-on-itemcreated-itemdatabound.html

And hide the required cell:
( Section Accessing controls in edit/insert mode )
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Similar to this:

Copy Code
Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs)
    If TypeOf e.Item Is IGridInsertItem Then
        Dim cell As TableCell = TryCast(e.Item, GridEditableItem)("ColumnUniqueName")
        cell.Parent.Visible = False
    End If
End Sub

Hope this helps.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Phil
Top achievements
Rank 1
answered on 31 Aug 2015, 01:34 PM

Eyup,

That actually wouldn't work for me because i am dynamically creating a grid based on the form and not at a record level. By using your suggestion we would end up having to do that on every form we use the radgrid and that would end up being about 50 files. 

My solution ends up going in our grid generation class which then takes care of the insert display logic on every grid, so code is in one place only :)

 

Thanks for the suggestion though

  

Phil

0
Eyup
Telerik team
answered on 02 Sep 2015, 01:51 PM
Hi Phil,

I'm glad you've found a viable solution for your scenario. Since you mentioned "grid generation class", just please keep in mind that creating custom controls is beyond our support scope even if they are inherited directly from Telerik UI controls. If you happen to come across the need to implement something like this, you can use UserControls. Other than that, the logic seems fine.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Phil
Top achievements
Rank 1
answered on 02 Sep 2015, 02:45 PM

Well i guess im not really sure its technically considered a custom control since we're using all of telerik's samples in programatically generating a radgrid. Only thing we've done is organized telerik into a class and a method call that allows us to control what type of column control to load.

 

Everything starts with:

RadGrid grid = new RadGrid();

Then we just dynamically add columns with item/edit/insert templates as we go. As much as things are custom im not really sure its considered a custom control since we're using everything telerik provides and we're not creating any custom control objects?

Everything we've done is pretty much taken from the basic concepts of this links:

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/creating-a-radgrid-programmatically

 

So forgive me if i'm a little concerned when someone mentions that my issue may not be supported when its in your documentation as a way to do things.

One last note, is i wasn't really looking for logic (i probably should have phrased my post better), i was looking for a feature that a telerik grid may or may not have that would allow me to hide labels in an insert template. If i know that the feature exists then i can programmatically turn it off/on in our grid. In the end it was the InsertVisiblityMode feature that allowed me to do what i wanted.

Thanks for your response 

0
Eyup
Telerik team
answered on 03 Sep 2015, 01:54 PM
Hello Phil,

Programmatic creation of RadGrid is perfectly viable and supported. You can even change the structure of the grid dynamically:
http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/defining-structure/changing-the-grid-structure-dynamically-on-postback

What I meant was something like this:
public class ModifiedRadGrid : RadGrid { } // custom internal logic
protected void Page_Load(object sender, EventArgs e)
{
    ModifiedRadGrid modifiedGrid = new ModifiedRadGrid();
}

In addition to the InsertVisibilityMode property that you've found helpful in your scenario, I want to make sure that you are also aware of the DefaultInsertValue property:
<telerik:GridBoundColumn ... DefaultInsertValue="Accept">

Please do not hesitate to turn to us if some questions or concerns arise.

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Phil
Top achievements
Rank 1
answered on 03 Sep 2015, 02:43 PM

Thanks Eyup!

That actually will be a handy option we might someday implement when we need!

And we are definitely not creating a custom control, so that's good news. 

I was thinking of someday creating a scaled down project as an example for people who want to create a totally data driven dynamic grid but it feels like we'd be giving away our secret sauce hehe. It would help our future support tickets though if we just had a simplified version of our grid. 

 

Thanks again

 

 

0
Eyup
Telerik team
answered on 08 Sep 2015, 01:36 PM
Hi Phil,

It is perfectly understandable to keep your company logic and data private, however, if you decide to share a sample project built using a dummy source with our community, you can always create and submit a code-library:
http://www.telerik.com/support/code-library/aspnet-ajax/grid

Regards,
Eyup
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Phil
Top achievements
Rank 1
Answers by
Phil
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or