DataBinding:“System.Data.DataRowView不包含名为"NewsID"的属性. 20

usingSystem;usingSystem.Data;usingSystem.Configuration;usingSystem.Collections;usingS... 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;
public partial class admin_newsList : System.Web.UI.Page
{
OperationData op = new OperationData();
adminData ad = new adminData();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Session["admin"] == null)
{
Response.Redirect("adminLogin.aspx");
}
else
{
DataBindNewsList("select * from News");
}
}
}
public void DataBindNewsList(string sql)
{
this.GridView1.DataSource = op.GetDataSet(sql);
this.GridView1.DataBind();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName.Equals("editNews"))
{
string newsid = GridView1.DataKeys[index].Value.ToString();
Response.Redirect("editNews.aspx?id=" + newsid + "");
}
}
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
if (DropDownList1.SelectedValue.Equals("按标题"))
{
DataBindNewsList("select * from News where NewsTitle like '%" + this.TextBox1.Text.Trim() + "%'");
}
if (DropDownList1.SelectedValue.Equals("按作者"))
{
DataBindNewsList("select * from News where NewsAuthor like '%" + this.TextBox1.Text.Trim() + "%'");
}
if (DropDownList1.SelectedValue.Equals("按内容"))
{
DataBindNewsList("select * from News where NewsContent like '%" + this.TextBox1.Text.Trim() + "%'");
}
if (DropDownList1.SelectedValue.Equals("按类别"))
{
DataBindNewsList("select * from Type where Typename like '%" + this.TextBox1.Text.Trim() + "%'");
}

}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string newsid = this.GridView1.DataKeys[e.RowIndex].Value.ToString();
string sql = "delete News where NewsID=" + newsid + "";
if (ad.ExecuteSQL(sql) != 0)
{
Response.Write("<script>alert('删除成功!')</script>");
DataBindNewsList("select * from News");
}
else
{
Response.Write("<script>alert('删除未成功,请重新删除!')</script>");
}
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
DataBindNewsList("select * from News");
}
}
请大家帮我看看
展开
 我来答
qinnan851
2013-08-01 · TA获得超过104个赞
知道小有建树答主
回答量:239
采纳率:0%
帮助的人:181万
展开全部
你控件绑定的数据源列名你看过有没有NewsID或者是数据库的列名根本不叫NewsID~这个在c#里是大小写敏感的
追问
我检查过,有的,绑定里也有
reaver88
2013-08-14 · 超过10用户采纳过TA的回答
知道答主
回答量:52
采纳率:0%
帮助的人:31.9万
展开全部
是一直抱错还是偶尔报错呢?
把op.GetDataSet(sql)的代码贴出来看看!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式