对于一个错误说明
的按钮,我一直有一个非常奇怪的,可能是非常明显的错误编译器错误消息:CS1061:' admin_roles_aspx'不包含 ' DeleteRole'的定义没有扩展方法' DeleteRole' 接受类型' admin_roles_aspx'的第一个参数。可以找到 (您是否缺少using指令或程序集引用?)
首先我有' Button1'使用" DeleteRole"作为OnCommand如下
<asp:GridView runat="server" ID="UserRoles" AutoGenerateColumns="false"
CssClass="list" AlternatingRowStyle-CssClass="odd" GridLines="none"
>
<Columns>
<asp:TemplateField>
<HeaderTemplate>Role Name</HeaderTemplate>
<ItemTemplate>
<%# Eval("Role Name") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>User Count</HeaderTemplate>
<ItemTemplate>
<%# Eval("User Count") %>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderTemplate>Delete Role</HeaderTemplate>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" OnCommand="DeleteRole" CommandName="DeleteRole" CommandArgument='<%# Eval("Role Name") %>' Text="Delete" OnClientClick="return confirm('Are you sure?')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
然后我有&#39; DeleteRole&#39;在roles.aspx.cs中创建
public partial class roles : System.Web.UI.Page
{
private bool createRoleSuccess = true;
private void Page_PreRender()
{
// Create a DataTable and define its columns
DataTable RoleList = new DataTable();
RoleList.Columns.Add("Role Name");
RoleList.Columns.Add("User Count");
string[] allRoles = Roles.GetAllRoles();
// Get the list of roles in the system and how many users belong to each role
foreach (string roleName in allRoles)
{
int numberOfUsersInRole = Roles.GetUsersInRole(roleName).Length;
string[] roleRow = { roleName, numberOfUsersInRole.ToString() };
RoleList.Rows.Add(roleRow);
}
// Bind the DataTable to the GridView
UserRoles.DataSource = RoleList;
UserRoles.DataBind();
if (createRoleSuccess)
{
// Clears form field after a role was successfully added. Alternative to redirect technique I often use.
NewRole.Text = "";
}
}
private void DeleteRole(object sender, CommandEventArgs e)
{
try
{
Roles.DeleteRole(e.CommandArgument.ToString());
ConfirmationMessage.InnerText = "Role '" + e.CommandArgument.ToString() + "' was deleted.";
}
catch (Exception ex)
{
ConfirmationMessage.InnerText = ex.Message;
}
}
有没有人有任何建议,因为它现在开始让我感到沮丧(可能是因为我的编程缺乏经验)。提前谢谢,如果我是白痴,请保持温柔,因为我的技能显然不是很好。感谢。