0

Is it possible to create a content and edit template to be inserted within a GridViewTemplateColumn so that one can reuse it and not repeatedly insert the templates into their html?

I have around 15 columns that all need similar functionality (Having text during content phase and a multiline textbox in edit) and it works fine by using a template column.

However, if I want to make changes to the templates, i'll need to change them all.

I've tried everything that I can think of to get this to work from creating a custom control to extending the template column but I may just not know enough about DotVVM to do it.

Any help would be greatly appreciated.

Solved! Solution below.

public class MultiLineTextColumn : GridViewTextColumn
{

    public override void CreateEditControls(IDotvvmRequestContext context, DotvvmControl container)
    {
        var textBox = new TextBox();
        textBox.FormatString = FormatString;
        textBox.ValueType = ValueType;
        textBox.SetBinding(TextBox.TextProperty, GetValueBinding(ValueBindingProperty));

        textBox.Type = TextBoxType.MultiLine;

        container.Children.Add(textBox);
    }
}

In DotvvmStartup.cs

    config.Markup.Controls.Add(new DotvvmControlConfiguration
    {
        TagPrefix = "cc",
        Namespace = "Project.Controls",
        Assembly = "Project"

    });
Aron
  • 3
  • 3
  • I think using Custom control might be the right approach. Can you show us what have you tried? I would rather not post the whole solution. – Dusan Janosik Oct 03 '17 at 17:55

1 Answers1

0

You can create your own column type.

  1. Create a class which inherits from GridViewColumn.

  2. Override CreateControls, CreateEditControls and CreateInsertControls and build the control tree inside the cell.

If you wan to make a multi-line edit cell, you can modify the default GridViewTextColumn - just set the Type to MultiLine in the CreateEditControls method.

  1. Then you need to register the control in DotvvmStartup.
Tomáš Herceg
  • 1,595
  • 1
  • 13
  • 18
  • Thanks for the help! I've updated the main post. Also would like to note that I believe the documentation is outdated or perhaps the methods available to the configuration are different for me than what is listed. – Aron Oct 04 '17 at 14:29