locked
User control with nested GridView stops intellisense from working RRS feed

  • Question

  • User1285297674 posted

    I asked this question a while ago, but I probably didn't describe it well enough, so here goes again!

    I have a user control that wraps a gridview. The user control exposes the Columns property in its class definition.

    Any page that uses this user control can still use the familiar GridView Columns tag in the markup (as roughly illustrated below) and the page works as expected. The wrapped gridview user control renders fine with the columns specified.

    The problem with this is that intellisense stops working on the Columns element and any element inside the Columns element in the User control markup definition (e.g. BoundField, TempalteField, LinkButton etc) and the Accessibilty check throws up warnings for these user controls. It means you have to remember or lookup the attributes for each tag you use, unless you can remember.

    Is there anyway to have Intellisense correctly function for nested items in this way or would you have to use a custom Control or something?

    This post (http://forums.asp.net/t/1299374.aspx) looked promising - the item marked as answer I thought was a similar sort of problem.

    Many thanks

    ---

    Rough example code, not tested.


    User Control (WrappedGridview.ascx) markup:

    <div>
    <asp:GridView ID="gv" runat="server" ...>
    </asp:GridView>
    </div>



    User Control code behind (WrappedGridview.ascx.cs) code behind:

    ...
    public DataControlFieldCollection Columns
    {
    get { return gv.Columns; }
    }
    ...




    Page markup (SomePage.aspx):

    <uc1:WrappedGridview>
    <Columns>
    <asp:BoundField ...>
    <asp:TemplateField ...>
    <ItemTemplate>
    <asp:LinkButton ...>
    ...
    </ItemTemplate>
    </Columns>
    ...
    </uc1:WrappedGridview>


    Saturday, October 31, 2009 2:08 PM

Answers

  • User1285297674 posted

    I finally found the answer to this problem.

    I should of looked at the metadata for the existing Gridview control. When I did I saw this:

            //
            // Summary:
            //     Gets a collection of System.Web.UI.WebControls.DataControlField objects that
            //     represent the column fields in a System.Web.UI.WebControls.GridView control.
            //
            // Returns:
            //     A System.Web.UI.WebControls.DataControlFieldCollection that contains all
            //     the column fields in the System.Web.UI.WebControls.GridView control.
            [MergableProperty(false)]
            [DefaultValue("")]
            [Editor("System.Web.UI.Design.WebControls.DataControlFieldTypeEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            public virtual DataControlFieldCollection Columns { get; }

    So just by using this in my code the intellisense now works perfectly:

            [MergableProperty(false)]
            [DefaultValue("")]
            [PersistenceMode(PersistenceMode.InnerProperty)]
            public DataControlFieldCollection Columns
            {
                get { return gv.Columns; }
            }


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 22, 2009 1:49 PM