Gridview在当前上下文中不存在

时间:2015-09-09 14:18:32

标签: c# mysql asp.net

此错误

  

“'gv'在当前上下文中不存在”

当我尝试加载gridview时显示

。 这是我第一次看到这个错误。 我工作了很多来解决这个错误,并没有成功。 我需要做什么来编织这个错误并加载网格视图。 感谢。

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;

//Start table
builder.StartTable();

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.Write("One");

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.Write("Two");

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.CellFormat.HorizontalMerge = CellMerge.First;
builder.Write("Header");

builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.Previous;
builder.Write("Header");

builder.InsertCell();
builder.CellFormat.HorizontalMerge = CellMerge.None;
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.Write("Column");

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.First;
builder.Write("Column");
builder.EndRow();

//Insert second Row
builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.Write("One");

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.Write("Two");

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.Write("First");

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.None;
builder.Write("Second");

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.Write("Column");

builder.InsertCell();
builder.CellFormat.VerticalMerge = CellMerge.Previous;
builder.Write("Column");
builder.EndRow();

builder.CellFormat.VerticalMerge = CellMerge.None;
builder.CellFormat.HorizontalMerge = CellMerge.None;
for (int i = 0; i < 10; i++)
{
    builder.InsertCell();
    builder.Write("Cell 1");

    builder.InsertCell();
    builder.Write("Cell 2");

    builder.InsertCell();
    builder.Write("Cell 3");

    builder.InsertCell();
    builder.Write("Cell 4");

    builder.InsertCell();
    builder.Write("Cell 5");

    builder.InsertCell();
    builder.Write("Cell 6");
    builder.EndRow();
}

//End the table
builder.EndTable();

doc.Save(MyDir + "Out.docx");

1 个答案:

答案 0 :(得分:2)

尝试将Inherits的值设置为类的名称:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="usageDisp.aspx.cs" Inherits="WebApplication1.usageDisp" %>

来自MSDN

  

继承 - 为要继承的页面定义代码隐藏类。这个可以   是从Page类派生的任何类。此属性用于   CodeFile属性,包含源文件的路径   代码隐藏类。 Inherits属性在区分大小写时   使用C#作为页面语言,使用Visual时不区分大小写   基本作为页面语言。