重载方法未获取参数问题
调用this.New_DeleteCommand();方法时出现错误
“重载News_DeleteCommand方法未获取“0”参数”
不知道该获得什么参数,望各位大虾提醒,谢谢```在线等
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
DataSet dset=new DataSet();
stringconn= "Provider=Microsoft.Jet.OLEDB.4.0;DataSource=d:/news/mdb/etwldbs.mdb ";
string comm= "select id,SortName,title from news ";
OleDbDataAdapter odr=new OleDbDataAdapter(comm,conn);
odr.Fill(dset);
repeater1.DataSource=dset.Tables[0].DefaultView;
repeater1.DataBind();
}
}
private void News_DeleteCommand(object source,System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
if(e.CommandName== "dealnews ")
{
HtmlInputHidden hih=(HtmlInputHidden)e.Item.FindControl( "NewsID ");
int newsid=Convert.ToInt32(hih.Value);
this.DeleteNews(newsid);
}
}
private void DeleteNews(int ID)
{
OleDbConnection conn=new OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=d:/news/mdb/etwldbs.mdb ");
conn.Open();
string sql= "delete news where id=ID ";
OleDbCommand cmd=new OleDbCommand(sql,conn);
cmd.Parameters[ "@id "].Value=ID;
cmd.ExecuteNonQuery();
cmd.Dispose();
conn.Close();
conn.Dispose();
Response.Redirect( "dealnews.aspx ");
}
private void dealButton_Click(object sender, System.EventArgs e)
{
this.News_DeleteCommand();
}
------解决方案--------------------第一个参数:object source,---可以将News控件对象赋上
第二个参数:System.Web.UI.WebControls.RepeaterCommandEventArgs e 可以构造一个RepeaterCommandEventArgs 实例
RepeaterCommandEventArgs ee=new RepeaterCommandEventArgs();
ee.CommandName== "dealnews ";
this.News_DeleteCommand(this.News,ee);----