Click here to Skip to main content
15,908,437 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have my marginalworkers.aspx as


<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="marginalworkers.aspx.cs" Inherits="marginalworkers" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Population of Marginal Workers
<asp:GridView ID="GridView1" runat="server">




and a .cs file as marginalworkers.aspx.cs
C#
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class marginalworkers : System.Web.UI.Page
{
    DataSet ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        Bind();
    }
    public void Bind()
    {
        SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
        SqlDataAdapter da = new SqlDataAdapter("select * from marginalworkers", cn);
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();

    }
}

It is throwing an error as "The name 'GridView1' does not exist in the current context".Please suggest me a solution...
Posted
Updated 17-Aug-15 0:54am
v5

It's possible this has to do with your tags - you don't seem to close them.
Try changing this:
ASP.NET
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
To this:
ASP.NET
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server" />
And do the same with your other controls, including the GridView
 
Share this answer
 
Comments
Member 10585568 17-Aug-15 6:59am    
Sorry it was my mistake,I have that closing tag of <asp:content xmlns:asp="#unknown">..
I just missed it...
There are three possible solutions for this error:

1 – There are two classes with same name. Possibly you have renamed a page and created a new one, but you did not changed the name in the cs file. So make sure you have only one file with this name in your project. There may be two files with different name but same class name this may create problems.

2 – Multiple web.config files in your project. Make sure you have only one web.config file in your project. However you can have mulitple web.config files in your project but that has to be in particular format.

3 – The designer file is not refreshed.(As u said you are creating a website so ignore this)

Hope It Helps :)
 
Share this answer
 
v3
Comments
Member 10585568 17-Aug-15 6:58am    
Can you suggest me the steps to check the above,as i am new to .net
Sanket Saxena 17-Aug-15 7:02am    
If you are using a web project then check the folder were the marginalworkers.aspx and its .cs file placed and you will found marginalworkers.designer.cs file there.
just open it and find GridView1" if not exist then add it manually. Will work.
Member 10585568 17-Aug-15 7:16am    
I am not getting any add option to add that ".designer.cs" file.What to do??

I am developing a website not a web application.
Do i need to have this designer.cs file...
As i saw something which tells that websites do not required designer.cs file..
I am refering to below link
http://www.codeproject.com/Tips/714968/Regenerate-aspx-designer-cs-Files-When-Corrupted
Sanket Saxena 17-Aug-15 7:37am    
I updated my solution plz check
Member 10585568 17-Aug-15 7:45am    
I have checked all the solutions.It is not working.I have only one web.config file, i don't have multiple class with same name... :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900