我遇到的问题是我需要通过单击按钮传递多个参数。我有一个从 sqlquery 打印出值的转发器对象,并且该按钮具有来自同一查询的参数
这是我的中继器:
<asp:Repeater ID="Edit_Repeater" runat="server" DataSourceID="Edit_Repeater_Source">
<HeaderTemplate>
<table class="u_Repeater">
<tr>
<th>
Group Name:
</th>
<th>
Permission Level:
</th>
<th>
Remove:
</th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%#DataBinder.Eval(Container.DataItem, "Group_Name")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "Name")%>
</td>
<td>
<asp:Button ID="Submit_Remove" runat="server" Text="Remove Permission" OnClick="Remove_Permission" CommandArgument='<%# Eval("GID") + ";" + Eval("PID") %>' />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
这是我背后的代码:
protected void Remove_Permission(object sender, CommandEventArgs e)
{
string[] arg = new string[2];
string[] commandArgs = e.CommandArgument.ToString().Split(';');
float GID = float.Parse(arg[0]);
float PID = float.Parse(arg[1]);
string UID = User_ID.SelectedValue;
using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["app_migrationConnectionString"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("DELETE FROM Membership WHERE GID = @GID AND PID = @PID AND UID = @UID", connection);
cmd.Parameters.Add("@GID", SqlDbType.BigInt, -1);
cmd.Parameters["@GID"].Value = GID;
cmd.Parameters.Add("@PID", SqlDbType.BigInt, -1);
cmd.Parameters["@PID"].Value = PID;
cmd.Parameters.Add("@UID", SqlDbType.NVarChar, -1);
cmd.Parameters["@UID"].Value = UID;
try
{
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
}
catch (Exception ex)
{
throw ex;
}
}
}
我没有收到任何构建错误,但是当我运行该页面时,我收到一个编译错误消息:
“Remove_Permission”没有重载匹配委托“System.EventHandler”
我几乎肯定代码是正确的,那么问题是什么?