C# Asp.net及;c“错误:名称”;mygv“;在当前上下文中不存在
我试图将数据绑定到名为“mygv”的网格,但出现错误“名称“mygv”在当前上下文中不存在”。这里也有类似的问题,但提供的解决方案对我不起作用。这就是我所做的 new.aspx.csC# Asp.net及;c“错误:名称”;mygv“;在当前上下文中不存在,c#,asp.net,C#,Asp.net,我试图将数据绑定到名为“mygv”的网格,但出现错误“名称“mygv”在当前上下文中不存在”。这里也有类似的问题,但提供的解决方案对我不起作用。这就是我所做的 new.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;
using System.Text.RegularExpressions;
namespace DistrictEfts
{
public partial class _new : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void Generate_Efts(object sender, System.EventArgs e)
{
StreamReader sr=null;
DataTable dt = new DataTable();
DataRow dr;
string column1 = "";
string column2="";
string column3="";
string column4="";
string column5="";
string column6="";
string column7="";
string column8="";
string column9="";
try
{
sr = new StreamReader(Server.MapPath("~\\1623107554X.PAY"));
string eachline = "";
string[] colval = null;
int i = 0;
while (!sr.EndOfStream)
{
//Read line by line
eachline = sr.ReadLine();
//Formatting the file contents
string s = Regex.Replace(eachline , @"[^\w'""&:;-()-]+", " ,");
colval = eachline.Split(',');
if (i == 0)
{
column1 = colval[0];
column2 = colval[1];
column3 = colval[2];
column4 = colval[3];
column5 = colval[4];
column6 = colval[5];
column7 = colval[6];
column8 = colval[7];
column9 = colval[8];
dt.Columns.Add(column1);
dt.Columns.Add(column2);
dt.Columns.Add(column3);
dt.Columns.Add(column4);
dt.Columns.Add(column5);
dt.Columns.Add(column6);
dt.Columns.Add(column7);
dt.Columns.Add(column8);
dt.Columns.Add(column9);
i = i + 1;
}
//Add values in the datatable columns
else
{
dr = dt.NewRow();
dr[ column1] = colval[0];
dr[column2] = colval[1];
dr[column3] = colval[2];
dr[column4] = colval[3];
dr[column5] = colval[4];
dr[column6] = colval[5];
dr[column7] = colval[6];
dr[column8] = colval[7];
dr[column9] = colval[8];
dt.Rows.Add(dr);
}
}
sr.Close();
mygv.DataSource = dt;
mygv.DataBind();
}
catch (Exception ex)
{
}
finally
{
}
}
}
}
新建.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="new.aspx.cs" Inherits=" _new" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table cellpadding="0" cellspacing="0" width="800" align="center">
<tr>
<td height="60">
<p> District efts</p>
</td>
</tr>
<tr>
<td height="30" align="center">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
</tr>
<tr>
<td height="50" align="center">
<asp:Button ID="Button2" runat="server" Text="Generate Efts"
onclick="Generate_Efts" />
</td>
</tr>
<tr>
<td align="center">
<asp:GridView ID="mygv" runat="server" Width="400">
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
地区efts
我将非常感谢您的帮助。
谢谢。有几个问题。首先,asp.net 2.0中未使用属性CodeBehind。您应该改用代码文件
接下来,您不能将页面类放在名称空间中,如果可以的话,它必须与Inherits属性中提到的相同:TaskList vs TaskGridList。有几个问题。首先,asp.net 2.0中未使用属性CodeBehind。您应该改用代码文件
接下来,您不能将页面类放在命名空间中,如果可以的话,它必须与Inherits属性中提到的相同:TaskList vs TaskGridList。我解决了这个问题,因为我的页面类位于命名空间中,所以我将页面类的命名空间添加到Inherits属性中 是
现在改成
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="new.aspx.cs" Inherits=" DistrictEfts._new" %>
这对我很有效。我解决了这个问题,因为我的页面类位于名称空间中,所以我将页面类的名称空间添加到了Inherits属性中 是
现在改成
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="new.aspx.cs" Inherits=" DistrictEfts._new" %>
这对我有效。可能是您的designer.cs已损坏或未生成。请尝试为您的Web表单重新生成designer。它已生成@HassaanKhan。可能是您的designer.cs已损坏或未生成。请尝试为您的Web表单重新生成designer。它已生成@哈桑汗。