GridView:控件设计器

时间:2010-05-12 12:31:04

标签: c# asp.net gridview designer composite

我对GridView及其控件设计器有疑问。

我做了一个继承GridView的复合控件。我想在GridView控件的设计器中创建一些新创建的BoundField控件?这样我就可以从Available fields列表中选择自定义BoundField控件。

有人知道这个吗?

1 个答案:

答案 0 :(得分:0)

自定义绑定字段的示例

namespace CustomControls
{
public class CompositeBoundField : BoundField
{
    protected override object GetValue(Control controlContainer)
    {
        object item = DataBinder.GetDataItem(controlContainer);
        return DataBinder.Eval(item, this.DataField);
    }
}

public class CompositeCheckBoxField : CheckBoxField
{


    protected override object GetValue(Control controlContainer)
    {
        /*bool isChecked = false;
        if (this.DataField.ToLower() == "true")
            isChecked = true;

        object item = DataBinder.GetDataItem(controlContainer);
        return isChecked;
        */

        object item = DataBinder.GetDataItem(controlContainer);
        return DataBinder.Eval(item, this.DataField);
    }
}

}

并将其添加到配置

    <pages>
        <controls>

            <add assembly="App_Code" namespace="CustomControls" tagPrefix="cc"/>
        </controls>
    </pages>

然后在ASP.NET页面中使用它。希望这会有所帮助。