本文介绍了抛出错误为“名称'GridView1'在当前上下文中不存在”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的marginalworkers.aspx为





<%@ Page Language =C#MasterPageFile =〜/ MasterPage .masterAutoEventWireup =trueCodeFile =marginalworkers.aspx.csInherits =marginalworkersTitle =Untitled Page%>



< asp :Content ID =Content1ContentPlaceHolderID =ContentPlaceHolder1Runat =Server>

边缘工人人口

< asp: GridView ID =GridView1runat =server>









和.cs文件为marginalworkers.aspx.cs

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

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();

    }
}



由于当前上下文中不存在名称'GridView1'而引发错误。请给我一个解决方案...


It is throwing an error as "The name 'GridView1' does not exist in the current context".Please suggest me a solution...

推荐答案

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

对此:

To this:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server" />

并对其他控件执行相同操作,包括GridView

And do the same with your other controls, including the GridView



这篇关于抛出错误为“名称'GridView1'在当前上下文中不存在”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-10 17:24