The name 'Gridview1' does not exist in the current context

Hi - I added a gridview to me aspx page and i 'm trying to assing data to it from codebehind.

i'm getting this error..
The name 'Gridview1' does not exist in the current context      

Any idea why? Please help!!
mrperfect75000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gautham JanardhanCommented:
did u name it correctly..i.e is it's name gridview1

try commenting off that line and rebuilding
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fahad MukhtarDistinguished EngineerCommented:
try to look for
this.GridView1  (in C#)
or
Me.GridView1 (in VB.net)
using intellisense in the Codebehind
You may be providing a vriablename with wrong case
0
mrperfect75000Author Commented:
yes it is named correctly, Gridview1 in both aspx and aspx.cs

i commented it out in code behind and it rebuilds...nut not when its not commente dout
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

mrperfect75000Author Commented:
How do i use intellisense? Could you please explain what that is... I tried searching entire solution for this.GridView1 but i couldnt find it anywhere....
0
Gautham JanardhanCommented:
this usualy happens in .Net

dont know why..
can u try after closing the application and then ropening
0
mrperfect75000Author Commented:
Yes - i read that in a forum and tried it -  ieven exluded the files from the project and closed and reopened - same thing.
0
Gautham JanardhanCommented:
u said u searched in code behind rt..

can try takig the html source and trying it there..another option would be to delete that control and plcae another one
0
mrperfect75000Author Commented:
Yes - i searched all open files - including code behind.

Ok - i ran the program it ran but gave me an error page - i viewed the source and found this...

private global::System.Web.UI.WebControls.GridView @__BuildControlGridView1() {
Line 426:              global::System.Web.UI.WebControls.GridView @__ctrl;
Line 427:              
Line 428:              #line 50 "C:\svn\webservice\Default.aspx"
Line 429:              @__ctrl = new global::System.Web.UI.WebControls.GridView();
Line 430:              
Line 431:              #line default
Line 432:              #line hidden
Line 433:              this.GridView1 = @__ctrl;
Line 434:              @__ctrl.ApplyStyleSheetSkin(this);
Line 435:              
Line 436:              #line 50 "C:\svn\webservice\Default.aspx"
Line 437:              @__ctrl.ID = "GridView1";



I have tried deleting gridview1 and adding a new one...
0
Gautham JanardhanCommented:
when u run without the error cde is the grid view getting displayed..after setting the datasource (not thru code)
0
mrperfect75000Author Commented:
I havent tried it like that. My data source is an array list - this is what i'm doing...I dont think i can add that as a data source in design view.

ArrayList eventArrayList= ArrayList.Adapter(eventArray);
Gridview1.Datasource = eventArrayList;
Gridview1.Databind();
0
Gautham JanardhanCommented:
i dont think it has to do with any thing u are doing it's  bug in .Net i think..

0
mrperfect75000Author Commented:
oh Ok - I tried all the things here but nothing works!

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=200532&SiteID=1
0
mrperfect75000Author Commented:
I did this over again - diff solution - diff computer and it still gives me the same error. I'm thinking it might be a problem else where not a bug?
0
tovvenkiCommented:
Hi,
can you check the following discussion
http://forums.asp.net/thread/1336317.aspx

are you using Visual Web developer or Visdual Studio. If possible can you paste the sources of  .aspx and the code behind files. So that we can check it and provide a solution.

Kind regards
venki
0
mrperfect75000Author Commented:
I am using Visual Studio...this is my code behind..

ArrayList eventArrayList= ArrayList.Adapter(eventArray);
Gridview1.Datasource = eventArrayList;
Gridview1.Databind();

here is aspx

 <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" Width="348px">
                </asp:GridView>
0
tovvenkiCommented:
when u comment the following lines
ArrayList eventArrayList= ArrayList.Adapter(eventArray);
Gridview1.Datasource = eventArrayList;
Gridview1.Databind();

and try to run is the application running

Kind regards
Venki
0
tovvenkiCommented:
this is strange, I copy pasted your code to a new webform and when I built the solution I got the same error message. I then tried accessing GridView1 using the this keyword like
this.Gridview1.Datasource = eventArrayList;
this.Gridview1.Databind();

and when I built the project again it worked without any errors. Added to this now when I remove the this keyword and built the project it worked again.
Something strange is happening in VS.Net
can you try it and see whether it works for you also

Kind regards
Venki
0
mrperfect75000Author Commented:
Thanks for trying - I put in thte this keyword and i get this error..

Error      1      '_Default' does not contain a definition for 'Gridview1'      when i comment it out - it complies....
0
mrperfect75000Author Commented:
Hey guys - i found the solution - kinda wierd!!
Apparently C# is case sensitive and i had Gridview1 instead of GridView1
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.