System.EventArgs 并不包含 CommandName 的定义
不知道什么地方出问题了,麻烦大家帮我看看前台代码:<%@PageLanguage="C#"MasterPageFile="~/admin/MasterPage.maste...
不知道什么地方出问题了,麻烦大家帮我看看
前台代码:
<%@ Page Language="C#" MasterPageFile="~/admin/MasterPage.master" AutoEventWireup="true" CodeFile="User.aspx.cs" Inherits="User" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Conut1" Runat="Server">
<table width="775" border="0" cellspacing="2" cellpadding="0" align="center">
<tr>
<td align="center" class="Login1" height="25" width="150">管理帐户</td>
<td align="center" class="Login1">管理密码</td>
<td align="center" class="Login1">添加时间</td>
<td align="center" class="Login1">删除</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td align="center" class="Login2" height="25"><%#Eval("UserAdmin") %></td>
<td align="center" class="Login2"><%#Eval("UserPwd")%></td>
<td align="center" class="Login2"><%#Eval("Time")%></td>
<td align="center" class="Login2">
<asp:LinkButton ID="LinkButton1" CommandName='<%#Eval("Id") %>' OnCommand="DelComm_Click" OnClientClick="return confirm('确定要删除吗?');" runat="server">删除</asp:LinkButton></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</asp:Content>
后台代码:
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class User : System.Web.UI.Page
{
db news = new db();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Admin"] == null)
{
Response.Redirect("./Default.Aspx");
}
OleDbConnection Conn = new OleDbConnection(news.conn2);
OleDbDataAdapter Da = new OleDbDataAdapter("select * from Admin", Conn);
DataSet Ds = new DataSet();
Da.Fill(Ds, "Admin");
Repeater1.DataSource = Ds.Tables[0].DefaultView;
Repeater1.DataBind();
}
protected void DelComm_Click(object sender, EventArgs e)
{
int ID = Convert.ToInt32(e.CommandName);
OleDbConnection Conn = new OleDbConnection(news.conn2);
Conn.Open();
OleDbCommand Cmd = new OleDbCommand("delete from Admin where Id=" + ID, Conn);
Cmd.ExecuteNonQuery();
Conn.Close();
Response.Redirect("./User.aspx");
}
} 展开
前台代码:
<%@ Page Language="C#" MasterPageFile="~/admin/MasterPage.master" AutoEventWireup="true" CodeFile="User.aspx.cs" Inherits="User" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Conut1" Runat="Server">
<table width="775" border="0" cellspacing="2" cellpadding="0" align="center">
<tr>
<td align="center" class="Login1" height="25" width="150">管理帐户</td>
<td align="center" class="Login1">管理密码</td>
<td align="center" class="Login1">添加时间</td>
<td align="center" class="Login1">删除</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr>
<td align="center" class="Login2" height="25"><%#Eval("UserAdmin") %></td>
<td align="center" class="Login2"><%#Eval("UserPwd")%></td>
<td align="center" class="Login2"><%#Eval("Time")%></td>
<td align="center" class="Login2">
<asp:LinkButton ID="LinkButton1" CommandName='<%#Eval("Id") %>' OnCommand="DelComm_Click" OnClientClick="return confirm('确定要删除吗?');" runat="server">删除</asp:LinkButton></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</asp:Content>
后台代码:
using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class User : System.Web.UI.Page
{
db news = new db();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Admin"] == null)
{
Response.Redirect("./Default.Aspx");
}
OleDbConnection Conn = new OleDbConnection(news.conn2);
OleDbDataAdapter Da = new OleDbDataAdapter("select * from Admin", Conn);
DataSet Ds = new DataSet();
Da.Fill(Ds, "Admin");
Repeater1.DataSource = Ds.Tables[0].DefaultView;
Repeater1.DataBind();
}
protected void DelComm_Click(object sender, EventArgs e)
{
int ID = Convert.ToInt32(e.CommandName);
OleDbConnection Conn = new OleDbConnection(news.conn2);
Conn.Open();
OleDbCommand Cmd = new OleDbCommand("delete from Admin where Id=" + ID, Conn);
Cmd.ExecuteNonQuery();
Conn.Close();
Response.Redirect("./User.aspx");
}
} 展开
2个回答
展开全部
<asp:LinkButton ID="LinkButton1" CommandName="<%#Eval("Id") %>"OnCommand="DelComm_Click" OnClientClick="return confirm('确定要删除吗?');" runat="server">删除</asp:LinkButton>
你再试下,看好了没?CommandName的属性要用“”括着的
这是我用gridview写的
<asp:LinkButton id="lbtnSetVote" runat="server" CommandName="setVote">设为当前选举</asp:LinkButton>
你再试下,看好了没?CommandName的属性要用“”括着的
这是我用gridview写的
<asp:LinkButton id="lbtnSetVote" runat="server" CommandName="setVote">设为当前选举</asp:LinkButton>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询