Manage an ASP.Net server using a GridView control as a property

I am creating a custom server control that works in conjunction with a GridView control. I have the following code in my server control that defines a GridView control:

[Category("Data")]
[Description("The associated GridView control")]
public GridView GridViewControl { get; set; }

When Iโ€™m in the designer and I drag my control to the surface and view its properties in the properties window, I see where it says โ€œGridViewControlโ€ and next to it, where I can enter the identifier GridView control there is a dropbox from which I can Select the GridView control that is already part of the page. After selecting the GridView control from dropbox, enter the following code:

<cc1:MyCustomControl runat="server" ID="MyCustomControl1" GridViewControl="GridView1" />
<asp:GridView runat="server" ID="GridView1" ...

So, everything looks good during development. However, if I try to run the code, the application crashes because it is unable to convert the string name "GridView1" to a reference to the GridView1 object.

I assume this is because I am missing some code that I need to include in my custom server control code, but I could not find any examples of such a server control. Is this really my problem or is there something else or more that I am missing in my code so that everything works fine at runtime?

+4
source share

Source: https://habr.com/ru/post/1652776/


All Articles