本文介绍了无法调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用命令名删除gridview行所以

当我调试时,来自gridviewbind();

deleteCart(pic);



它停止了,它没有进入public void deleteCart(string orderID),可能有什么问题?







i wants to delete gridview row using command name so
when i debug , from gridviewbind();
deleteCart(pic);

it stops,and it is not entering into public void deleteCart(string orderID), what could be a problem?



protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            gridviewbind();
        }
    }




public void gridviewbind()
    {
        SqlConnection con = new SqlConnection("constring1");
        string str = "select * from Products INNER JOIN orders on Products.picID=orders.productID";
        SqlCommand cmd = new SqlCommand(str, con);
        con.Open();
        DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("picID", typeof(int)));
        dt.Columns.Add(new DataColumn("title", typeof(string)));
        dt.Columns.Add(new DataColumn("price", typeof(int)));
        dt.Columns.Add(new DataColumn("dateAdded", typeof(DateTime)));
        dt.Columns.Add(new DataColumn("picURL", typeof(string)));
        SqlDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            DataRow dr = dt.NewRow();
            dr["picID"] = Convert.ToInt32(reader["picID"]);
            dr["title"] = reader["title"];
            dr["price"] = Convert.ToInt32(reader["price"]);
            dr["dateAdded"] = reader["dateAdded"];
            dr["picURL"] = ResolveUrl("~/images/" + reader["picURL"]);
            dt.Rows.Add(dr);
        }
        reader.Close();
        con.Close();
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }




protected void Gridview1_RowCommand(object sender, GridViewCommandEventArgs e)
   {

       if (e.CommandName == "removeRow")
       {
           string pic = Convert.ToString(e.CommandArgument);
           //  GridViewRow row = GridView1.Rows[pic];

           //     deleteCart(row.Cells[1].Text.ToString());
           gridviewbind();
           deleteCart(pic);

       }

   }







public void deleteCart(string orderID)
    {
        using (SqlConnection con = new SqlConnection("constring1"))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = "delete from orders where orderID=@orderID";
                cmd.Connection = con;
                cmd.CommandType = CommandType.Text;

                cmd.Parameters.AddWithValue("@orderID", orderID);
                con.Open();
                var temp = cmd.ExecuteNonQuery();
                con.Close();
            }
        }
    }

推荐答案

Hi Friend....

Your seem good.... I would like to suggest you that please check whether following lines of code passing EXACT values as you want or NOT....

Use Degubber to do that....

<pre lang="c#">if (e.CommandName == "removeRow")
{
string pic = Convert.ToString(e.CommandArgument);

gridviewbind();
deleteCart(pic);

}



......

还...放函数 deleteCart(pic)上面的函数 gridviewbind()





然后检查结果..


......
And also...put the function deleteCart(pic)above the function gridviewbind()


Then check the result..



这篇关于无法调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 00:05