Solved

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

Posted on 2007-03-24
19
3,059 Views
Last Modified: 2008-01-09
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!!
0
Comment
Question by:mrperfect75000
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 5
  • 3
  • +1
19 Comments
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 220 total points
ID: 18787470
did u name it correctly..i.e is it's name gridview1

try commenting off that line and rebuilding
0
 
LVL 19

Assisted Solution

by:Desp
Desp earned 60 total points
ID: 18787480
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
 

Author Comment

by:mrperfect75000
ID: 18787487
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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 

Author Comment

by:mrperfect75000
ID: 18787492
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 18787493
this usualy happens in .Net

dont know why..
can u try after closing the application and then ropening
0
 

Author Comment

by:mrperfect75000
ID: 18787503
Yes - i read that in a forum and tried it -  ieven exluded the files from the project and closed and reopened - same thing.
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 18787507
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
 

Author Comment

by:mrperfect75000
ID: 18787515
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 18787522
when u run without the error cde is the grid view getting displayed..after setting the datasource (not thru code)
0
 

Author Comment

by:mrperfect75000
ID: 18787526
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
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 18787528
i dont think it has to do with any thing u are doing it's  bug in .Net i think..

0
 

Author Comment

by:mrperfect75000
ID: 18787530
oh Ok - I tried all the things here but nothing works!

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=200532&SiteID=1
0
 

Author Comment

by:mrperfect75000
ID: 18788281
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
 
LVL 21

Expert Comment

by:tovvenki
ID: 18790978
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
 

Author Comment

by:mrperfect75000
ID: 18791008
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
 
LVL 21

Expert Comment

by:tovvenki
ID: 18791039
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
 
LVL 21

Assisted Solution

by:tovvenki
tovvenki earned 220 total points
ID: 18791111
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
 

Author Comment

by:mrperfect75000
ID: 18793054
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
 

Author Comment

by:mrperfect75000
ID: 18793487
Hey guys - i found the solution - kinda wierd!!
Apparently C# is case sensitive and i had Gridview1 instead of GridView1
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question