日期:2014-05-20  浏览次数:20491 次

repeater控件附加删除按钮问题
我想给repeater控件的最后一列添加一个删除按钮   那个按钮绑定行的id   然后通过点击删除按钮来删掉这一行数据
我是这么写的
        后台:
        public   void   DeleteNews(int   NewsId)
        {
                DataTier   dt   =   new   DataTier();
                string   sql   =   "delete   from   Edu_News   where   newsid= ' "+NewsId+ " ' ";
                dt.RunUpdateSql(sql);
                InitRepeater();
                Response.Write( " <script> alert( '删除数据项成功! '); </script> ");
        }
        前台:
        <asp:Button   ID= "Button1 "   runat= "server "   Text= "删除 "   OnClick= ' <%#DeleteNews(DataBinder.Eval(Container.DataItem, "newsid "))   %> '/>

        我想应该是onclick这写的不对吧?请大家给帮帮忙   多谢拉

------解决方案--------------------
try:

HtmlButton + Js + LinkButton + __doPostBack + RaisePostBackEvent
------解决方案--------------------
改成 OnClick=DeleteNews( <%# DataBinder.Eval(Container.DataItem, "newsid ") %> ) 试试
------解决方案--------------------
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
…………………………
sqltmp = "delete from a where ID= " + ID.Text;

…………………………
…………………………
}
以前用过的代码
------解决方案--------------------
public void DeleteNews(int NewsId) ---这里你是传参数为int 而非string类型
{
DataTier dt = new DataTier();
string sql = "delete from Edu_News where newsid= "+NewsId+ " "; --所以这里改动
dt.RunUpdateSql(sql);
InitRepeater();
Response.Write( " <script> alert( '删除数据项成功! '); </script> ");
}
在后台写代码
public void DeleteNews(int NewsId)
{
objConDB = new ConDB();
objConDB.DeleteGarnerInfoByGarnerID(NewsId); --调用删除语句的方法

bindRepeater();
}

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Manager ")
{
DeleteNews(6); --这里我写死了,
}
}
前台:
<asp:Button ID= "btnaa " CommandName= "Manager " Text= "Manager " Runat= "server "> </asp:Button>
------解决方案--------------------
前台
<asp:TemplateColumn HeaderText= "操作 ">
<ItemTemplate>
<asp:LinkButton Text= "删除 " ID= "Btn_del " runat= "server " CommandName= "Delete " CommandArgument= ' <%#Eval( "id ")%> '> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
后台:
public void ItemsGrid_Command(object sender,DataGridCommandEventArgs e)
{
switch(((LinkButton)e.CommandSource).CommandName)