0

I have a question regarding the GridView and the Control Designer of it.

I've made a composite control inherited of the GridView. I would like to make some new created BoundField controls available in the designer of the GridView control? So that I can select the custom BoundField control from the Available fields list.

Anyone got a clue about this one?

4

1 回答 1

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 页面中使用它。希望这可以帮助。

于 2010-05-12T20:06:07.693 回答