我想在repeater中实现行的删除,但是一当即删除按钮就出现下面的问题,请各位高手帮我看下,十分感谢!“/Repeater”应用程序中的服务器错误。
--------------------------------------------------------------------------------回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。 界面设计:
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate>
<table border="1">
<tr>
<td><b>删除</b></td>
<td><b>序号</b></td>
<td><b>姓名</b></td>
<td><b>科目</b></td>
<td><b>成绩</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Button ID="button1" runat="server" CommandName="Delete" Text="删除" /></td>
<td> <%# Eval("xuhao") %> </td>
<td> <%# Eval("name") %> </td>
<td> <%# Eval("subject") %> </td>
<td> <%# Eval("grade") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate> </asp:Repeater>代码:
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataView dv = new DataView();
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(); protected void Page_Load(object sender, EventArgs e)
{
string conn1 = "Data Source=lgb;Integrated Security=SSPI;Initial Catalog=test;";
conn = new SqlConnection(conn1);
GetSource();
if (!IsPostBack)
{
BindData();
}
} private void GetSource()
{
conn.Open();
string sql = "select * from chengji";
da = new SqlDataAdapter(sql, conn);
da.Fill(ds);
dv = ds.Tables[0].DefaultView;
BindData();
conn.Close();
} private void BindData()
{
Repeater1.DataSource = dv;
Repeater1.DataBind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
conn.Open();
string xuhao=e.CommandArgument.ToString();
string sqldel = "delete from chengji where xuhao='" + xuhao + "'";
cmd = new SqlCommand(sqldel, conn);
cmd.ExecuteNonQuery();
BindData();
conn.Close();
}
}
--------------------------------------------------------------------------------回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。 界面设计:
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate>
<table border="1">
<tr>
<td><b>删除</b></td>
<td><b>序号</b></td>
<td><b>姓名</b></td>
<td><b>科目</b></td>
<td><b>成绩</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><asp:Button ID="button1" runat="server" CommandName="Delete" Text="删除" /></td>
<td> <%# Eval("xuhao") %> </td>
<td> <%# Eval("name") %> </td>
<td> <%# Eval("subject") %> </td>
<td> <%# Eval("grade") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate> </asp:Repeater>代码:
SqlDataAdapter da = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
DataView dv = new DataView();
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection(); protected void Page_Load(object sender, EventArgs e)
{
string conn1 = "Data Source=lgb;Integrated Security=SSPI;Initial Catalog=test;";
conn = new SqlConnection(conn1);
GetSource();
if (!IsPostBack)
{
BindData();
}
} private void GetSource()
{
conn.Open();
string sql = "select * from chengji";
da = new SqlDataAdapter(sql, conn);
da.Fill(ds);
dv = ds.Tables[0].DefaultView;
BindData();
conn.Close();
} private void BindData()
{
Repeater1.DataSource = dv;
Repeater1.DataBind();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
conn.Open();
string xuhao=e.CommandArgument.ToString();
string sqldel = "delete from chengji where xuhao='" + xuhao + "'";
cmd = new SqlCommand(sqldel, conn);
cmd.ExecuteNonQuery();
BindData();
conn.Close();
}
}
不太理解
{
string orderNo = e.CommandArgument.ToString();
try
{
删除操作
}
catch (Exception ex)
{
......
}
}
<%@ Page EnableEventValidation="false" %>
if (e.CommandName == "Delete")
{
conn.Open();
string xuhao=e.CommandArgument.ToString();你的<asp:Button ID="button1" runat="server" CommandName="Delete" Text="删除" /></td>
都没有设置CommandArgument,上面的代码能通过吗?
<%@ Page EnableEventValidation="false" %>
设置为false 的话,,程序就不执行我itemcommand里面的事件了,因为我在itemcommand里面只写了1条语句
是:response.write("ss"), 但是页面没有任何输出,,,为什么哦