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");
}
}
请大家帮我看看 展开
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");
}
}
请大家帮我看看 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询