在选定的数据源上未找到名为“PaperState”的字段或属性。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Web.HttpException: 在选定的数据源上未找到名为“PaperState”的字段或属性。
源错误:
行 30: DataSet ds = paper.QueryUserPaperList();
行 31: GridView1.DataSource = ds;
行 32: GridView1.DataBind();
行 33: LabelPageInfo.Text = "当前(第" + (GridView1.PageIndex + 1).ToString() + "页 共" + GridView1.PageCount.ToString() + "页)";
行 34: }
源文件: e:\莫\在线考试资料\OnLineExamUpdate\Web\UserPaperList.aspx.cs 行: 32
堆栈跟踪:
[HttpException (0x80004005): 在选定的数据源上未找到名为“PaperState”的字段或属性。]
System.Web.UI.WebControls.BoundField.GetValue(Control controlContainer) +414
System.Web.UI.WebControls.BoundField.OnDataBindField(Object sender, EventArgs e) +60
System.Web.UI.Control.OnDataBinding(EventArgs e) +80
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +198
System.Web.UI.Control.DataBind() +12
System.Web.UI.Control.DataBindChildren() +214
System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +208
System.Web.UI.Control.DataBind() +12
System.Web.UI.WebControls.GridView.CreateRow(Int32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) +221
System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3012
System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +59
System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +12
System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +101
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +25
System.Web.UI.WebControls.DataBoundControl.PerformSelect() +140
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +68
System.Web.UI.WebControls.GridView.DataBind() +5
Web_UserPaperList.InitData() in e:\莫\在线考试资料\OnLineExamUpdate\Web\UserPaperList.aspx.cs:32
Web_UserPaperList.Page_Load(Object sender, EventArgs e) in e:\莫\在线考试资料\OnLineExamUpdate\Web\UserPaperList.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +13
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +45
System.Web.UI.Control.OnLoad(EventArgs e) +80
System.Web.UI.Control.LoadRecursive() +49
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3748
aspx代码:
<asp:GridView ID="GridView1" runat="server" AllowPaging="true" DataKeyNames ="UserID,PaperID" OnRowDataBound="GridView1_RowDataBound" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="8" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" Font-Size="13px" Width="100%" OnRowDeleting="GridView1_RowDeleting">
<Columns>
<asp:BoundField DataField="UserID" HeaderText="UserID" ReadOnly="True"/>
<asp:BoundField DataField="PaperID" Visible="False" HeaderText="PaperID" ReadOnly="True"/>
<asp:TemplateField HeaderText="用户姓名">
<ItemTemplate>
<asp:Label ID="Label2" runat="server"><%# Eval("UserName") %></asp:Label>
</ItemTemplate>
<HeaderStyle Wrap="False" />
</asp:TemplateField>
<asp:TemplateField HeaderText="所在部门">
<ItemTemplate>
<asp:Label ID="Label3" runat="server"><%# Eval("DepartmentName")%></asp:Label>
</ItemTemplate>
<HeaderStyle Wrap="False" />
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="UserID,PaperID" DataNavigateUrlFormatString="UserPaper.aspx?UserID={0}&PaperID={1}" DataTextField="PaperName" HeaderText="试卷(点击查看)" ItemStyle-Font-Bold="true"/>
<asp:TemplateField HeaderText="考试时间">
<ItemTemplate>
<asp:Label ID="Label5" runat="server"><%# Eval("ExamTime") %></asp:Label>
</ItemTemplate>
<HeaderStyle Wrap="False" />
</asp:TemplateField>
<asp:BoundField HeaderText="是否评阅" DataField="PaperState" />
<asp:CommandField ShowDeleteButton="True" HeaderText="删除" />
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
</asp:GridView>
cs代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using OnLineExam.BusinessLogicLayer;
public partial class Web_UserPaperList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string loginName = Session["UserID"].ToString();
Users user = new Users();
user.LoadData(loginName);
labUser.Text = user.UserName;
InitData();
}
}
//初始化试卷表格
protected void InitData()
{
Paper paper = new Paper();
DataSet ds = paper.QueryUserPaperList();
GridView1.DataSource = ds;
GridView1.DataBind();
LabelPageInfo.Text = "当前(第" + (GridView1.PageIndex + 1).ToString() + "页 共" + GridView1.PageCount.ToString() + "页)";
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
InitData();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < GridView1.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='Aqua'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string UserID = GridView1.DataKeys[e.RowIndex].Values[0].ToString(); //取出要删除记录的主键值1
int PaperID = int.Parse(GridView1.DataKeys[e.RowIndex].Values[1].ToString().Trim());//取出要删除记录的主键值2
Paper paper = new Paper();
if (paper.DeleteByProc(UserID, PaperID))
{
Response.Write("<script language=javascript>alert('成功删除!')</script>");
}
else
{
Response.Write("<script language=javascript>alert('删除失败!')</script>");
}
InitData();
}
}
[解决办法]
查询语句中没有PaperState字段
[解决办法]
异常详细信息: System.Web.HttpException: 在选定的数据源上未找到名为“PaperState”的字段或属性。
(1)表里有这个字段吗?
(2)如果有的话,你的gv里面给列赋予这个字段了吗?
(3)你的查询语句里面有PaperState字段吗