asp.net repeater 的问题

来源:百度知道 编辑:UC知道 时间:2024/06/12 15:56:50
我都伤心死了 为什么一个很多人都遇到得repeater问题 就没有人愿意好好回答一下呢 要是你的回答你自己没试过 就别回答 来浪费大家的感情

类似这样
<asp:Button ID="btnDel" runat="server" OnClientClick="return confirm('确定删除?');"
CommandArgument=' <%#DataBinder.Eval(Container.DataItem,"id") %>' CommandName="del">删除 </asp:Button>
这种方法。当然删除按钮存在于repeater中。不能在后台代码段中直接操作。所以在后台通过Repeater_ItemCommand事件中来操作(这是我的理解)
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "del")
{
//根据id删除数据,重新绑定数据源
}

}
1.开始是这个问题:
回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true"......

使用if(!ispostback){ 数据绑定 } 之后
删除成功 但是页面显示的还是之前的数据 没有更新 刷新页面也不行

2.后来试着在Repeater1_ItemCo

当然是可以删除的.
例如if(!ispostback)
{
bind();//你自己写的绑定方法
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "del")
{
del(id);// 删除记录
bind();//重新绑定
}

}

这样也不行?