开发者

GridView: Control Designer

开发者 https://www.devze.com 2022-12-29 20:54 出处:网络
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

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?


Example of a custom bound field

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);
    }
}

}

And add this to the config

    <pages>
        <controls>

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

Then you use it in your ASP.NET page. Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号