SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
Thanks a lot :) – ar.gorgin Mar 28 '12 at 5:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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