后台  protected void Relist_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        Message mess = e.Item.DataItem as Message;
        Button btn = e.CommandArgument as Button;
        if (btn != null)
        {
            if(e.CommandName == "Edit")
            { 
                Response.Redirect("Test.aspx");
            }
            if (e.CommandName == "Delete")
            {
                string connectionString = WebGlobals.Config.DefaultConnectionString;
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    string del = String.Format("Delete * from [message] where title='{0}'", mess.Title);
                    SqlCommand command = new SqlCommand(del, connection);
                    connection.Open();                    command.ExecuteReader();
                    connection.Close();
                }
            }
        }
    }
前台:
<asp:Button ID="Edit" runat="server" OnClientClick="Edit" CommandArgument='<%# Eval("ID") %>' CommandName="Edit" Text="编辑" />
        <asp:Button ID="Delete" runat="server"  OnClientClick="Delete"  CommandArgument='<%# Eval("ID") %>' CommandName="Delete" Text="删除" />运行时提示: Microsoft JScript 运行时错误: 'Edit' 未定义   'Delete' 未定义请问我哪儿出错了呢?
        

解决方案 »

  1.   

    OnClientClick="Delete"还有这里,这两个删掉吧
      

  2.   

    CommandName="Delete" 
    CommandName="Edit"
    这两个事件没有在后台定义啊
      

  3.   

    CommandName="Delete"
    CommandName="Edit" 
    这两个删掉吧
      

  4.   

    Microsoft JScript 运行时错误: 'Edit' 未定义  'Delete' 未定义 
    很明显是JS错误,你删后台函数搞什么飞机~
      

  5.   


    你要控制什么嗫?
    后台只要你有写 CommandName="Edit" 这一句就可以
      

  6.   

    我还是不是很明白我错在哪儿?
    <asp:Button ID="Edit" runat="server" OnClientClick="Edit" CommandArgument=' <%# Eval("ID") %>' CommandName="Edit" Text="编辑" /> 
    这是在热评repeater里的一个按钮,我想通过这个编辑页面,e.CommandName == "Edit"  这样不可以选定吗?
      

  7.   

    你的思路是错误的
    <asp:Button ID="Edit" runat="server" OnClientClick="Edit" CommandArgument=' <%# Eval("ID") %>' //这里必需直接指定 CommandName="Edit" Text="编辑" /> 
      

  8.   

    OnClientClick="Edit"
    Edit方法未定义,JS错误!
      

  9.   


    删除了OnClientClick="Edit" 
    和OnClientClick="delete" 
    没有报错了。
    但是却无法完成编辑和删除功能,请各位高手指明。
      

  10.   


    把这段代码复制过去
    <asp:Button ID="Edit" runat="server" CommandArgument=' <%# Eval("ID") %>' CommandName="Edit" Text="编辑" />
    <asp:Button ID="Delete" runat="server"  CommandArgument=' <%# Eval("ID") %>' CommandName="Delete" Text="删除" />
      

  11.   

    eidt和delete是自带的还是自己写的啊
      

  12.   

    我删除了onclientclick="Delete"就无法触发啊。
      

  13.   

    已经全部调试出来,原来是 Button btn = e.CommandArgument as Button;
    应修改为 Button btn = e.CommandSource as Button;
    这样才能获取数据源,btn才能不为空,特此结贴。后台  protected void Relist_ItemCommand(object source, RepeaterCommandEventArgs e) 
        { 
            Message mess = e.Item.DataItem as Message; 
            Button btn = e.CommandArgument as Button; 
            if (btn != null) 
            { 
                if(e.CommandName == "Edit") 
                { 
                    Response.Redirect("Test.aspx"); 
                } 
                if (e.CommandName == "Delete") 
                { 
                    string connectionString = WebGlobals.Config.DefaultConnectionString; 
                    using (SqlConnection connection = new SqlConnection(connectionString)) 
                    { 
                        string del = String.Format("Delete * from [message] where title='{0}'", mess.Title); 
                        SqlCommand command = new SqlCommand(del, connection); 
                        connection.Open();                     command.ExecuteReader(); 
                        connection.Close(); 
                    } 
                } 
            } 
        } 
    前台: 
    <asp:Button ID="Edit" runat="server"  CommandArgument=' <%# Eval("ID") %>' CommandName="Edit" Text="编辑" /> 
            <asp:Button ID="Delete" runat="server" CommandArgument=' <%# Eval("ID") %>' CommandName="Delete" Text="删除" />