DotVVM-绑定仅代码用户控件中的值

时间:2019-03-26 10:16:44

标签: data-binding controls code-first dotvvm

我有一个想法,可以使用ComboBox和DataPager扩展GridView控件(以避免在所有页面上重复相同的代码),但是如果我在继承的MyGridView中创建ComboBox,则无法用数据填充它们。我应该怎么做才能进行正确的数据绑定?可以通过这种方式使用控件吗?

我继承了MyGridView:GridView并创建了受保护的ComboBox属性。在OnInit方法中,我设置ComboBox.DataSource = new List(){10,20,30}。在OnRender方法中,我添加了ComboBox.Render(...)

public class MyGridView : GridView
{
    protected int PageSize { get; set; } = 20;

    protected readonly List<int> pageSizeOptions = new List<int>() { 20, 50, 100 };

    protected ComboBox PageSizeComboBox { get; set; }

    protected override void OnInit(IDotvvmRequestContext context)
    {
        PageSizeComboBox = new ComboBox();
        PageSizeComboBox.DataSource = pageSizeOptions;
        PageSizeComboBox.SelectedValue = PageSize;
        PageSizeComboBox.SelectionChanged = () => new Task(UpdatePageSize);
    }

    public override void Render(IHtmlWriter writer, IDotvvmRequestContext context)
    {
        base.Render(writer, context);
        PageSizeComboBox.Render(writer, context);          
    }

...

MyGridView控件正确呈现GridView,但ComboBox呈现为空(<select data-bind="valueAllowUnset: true"></select>

0 个答案:

没有答案