我有一个Repeater显示SQL Server数据库中的行。
我的每一行都有一个编辑和删除按钮,但我无法在这些按钮后面成功编写代码。
以下是显示转发器的代码:
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<div>
<table>
<tr><th><%#Eval("Event_Title")%></th><td><asp:Button ID="LinkButton1" runat="server" CommandName="Edit" Text="Edittttt"></asp:Button></td><td><button>Delete</button></td></tr>
<tr><td>Event Group ID</td><td><%#Eval("Event_Group_Id") %></td></tr>
<tr><td>Event Type</td><td><%#Eval("Event_Type") %></td></tr>
<tr><td>Event ID</td><td><%#Eval("Event_Id") %></td></tr>
<br />
</table>
</div>
</ItemTemplate>
</asp:Repeater>
here是用户界面。
我尝试使用以下代码查看“编辑”按钮是否正常工作:
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "Edit":
Response.Write("Edit button clicked");
break;
default: break;
}
}
但我收到此错误消息:
无效的回发或回调参数。使用配置或&lt;%@ Page EnableEventValidation =&#34; true&#34;启用事件验证。 %GT;在一个页面中。出于安全考虑,此功能可验证回发或回调事件的参数是否来自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回调数据以进行验证。
以下是我的Page_Load代码: 我知道很多都是重复的,但我会及时整理它。谁能告诉我我需要做什么?
//Trying to display events using repeater
SqlConnection connR;
string connectionStringR = ConfigurationManager.ConnectionStrings[
"BallinoraDBConnectionString1"].ConnectionString;
connR = new SqlConnection(connectionStringR);
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Events", connR);
DataTable dt = new DataTable();
sda.Fill(dt);
Repeater1.DataSource = dt;
Repeater1.DataBind();
Response.Write("Hello");
SqlConnection conn;
SqlCommand comm;
string connectionString = ConfigurationManager.ConnectionStrings[
"BallinoraDBConnectionString1"].ConnectionString;
conn = new SqlConnection(connectionString);
comm = new SqlCommand( //where Event_Group = 'Upcoming
"SELECT Event_Id, Event_Group_Id, Event_Type, Event_Title FROM Events WHERE Event_Group_Id = 1",
conn);
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
if (lblGroupOneEvents.Text == "")
{
while (reader.Read())
{
lblGroupOneEvents.Text += "<div> <table> <tr><td>" + reader["Event_Title"] + "</td>" + "</tr><tr><td><button>Delete</button></td></tr></table> </div>";
}
// lblTest.Text += reader["Event_Id"] +"<br />";
}
else
{
;
}
reader.Close();
conn.Close();
SqlConnection conn1;
SqlCommand comm1;
string connectionString1 = ConfigurationManager.ConnectionStrings[
"BallinoraDBConnectionString1"].ConnectionString;
conn1 = new SqlConnection(connectionString);
comm1 = new SqlCommand( //where Event_Type = 'Upcoming
"SELECT Event_Id, Event_Group_Id, Event_Type, Event_Title FROM Events WHERE Event_Group_Id = 2",
conn);
conn.Open();
SqlDataReader reader1 = comm1.ExecuteReader();
while (reader1.Read())
{
lblGroupTwoEvents.Text += reader1["Event_Title"] + "<br />";
// lblGroupTwoEventsType.Text += reader1["Event_Id"] + "<br />";
}
reader.Close();
conn.Close();