Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.