0

I have a web part with SpGridview control .

<SharePoint:SPGridView ID="grid" AllowSorting="true" AllowFiltering="true"  CssClass="ms-listviewtable"  ClientIDMode="Static"
runat="server" AutoGenerateColumns="false"></SharePoint:SPGridView>

I defined a static function , when i use this grid in this ,i get error

An object reference is required for the nonstatic field

2

It is not related to SharePoint anyway.

In C#, Static members can operate only on static data and call static methods of the defining class. If you attempt to make use of nonstatic class data or call a nonstatic method of the class within a static member’s implementation,you will get error.

To use the grid in static method, you need to create instance of the webpart class and then use it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.