为什么我的值不会在gridview中更新?

时间:2014-07-28 17:55:30

标签: c# sql gridview updating

我有一个gridview,如果我点击更新,我将能够通过点击下拉列表中的值来更新发布的结构数量。但是,当我单击更新并检查时,值仍然与以前相同。请帮忙!

我在PPFabric类中的更新方法

    public int update()
    {
        string strConn = ConfigurationManager.ConnectionStrings
                        ["ZZFashionIMSConnectionString"].ToString();

        SqlConnection conn = new SqlConnection(strConn);

        SqlCommand cmd = new SqlCommand("UPDATE ProductionPlanFabric SET PPFabricIssued = @FStock WHERE ProductionPlanID = @ProductionPlanID AND FashionStyleID = @FashionStyleID AND FabricID = @FabricID", conn);

        cmd.Parameters.AddWithValue("@FStock", PPFabricIssued);
        cmd.Parameters.AddWithValue("@productionplanid", ProductionPlanID);
        cmd.Parameters.AddWithValue("@fashionstyleid", FashionStyleID);
        cmd.Parameters.AddWithValue("@fabricid", FabricID);

        conn.Open();
        int count = cmd.ExecuteNonQuery();
        conn.Close();

        if (count != 0)
            return 0;
        else
            return -2;
    }

更新IssueFabric webform中的按钮代码

    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            PPFabric objPPFabric = new PPFabric();
            objPPFabric.PPFabricIssued = Convert.ToInt32(ddlFabricIssued.SelectedValue);

            int errorCode = objPPFabric.update();

            if (errorCode == 0)
            {
                lblMessage.Text = "Fabric details has been updated successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
            else if (errorCode == -2)
            {
                lblMessage.Text = "Unable to update edited record as it was not found!";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }

        }
    }

视图待审结构页面中的数据源

    private void displayPendingFabric()
    {
        string strConn = ConfigurationManager.ConnectionStrings
                         ["ZZFashionIMSConnectionString"].ToString();
        SqlConnection conn = new SqlConnection(strConn);

        SqlCommand cmd = new SqlCommand("SELECT ProductionPlanID, FashionStyleID, FabricID, WarehouseID, PPStatus, PPFabricReqd, PPFabricIssued FROM ProductionPlanFabric WHERE PPStatus = 0 OR PPStatus = 2", conn);

        SqlDataAdapter daPPFabric = new SqlDataAdapter(cmd);
        DataSet result = new DataSet();

        conn.Open();
        daPPFabric.Fill(result, "ProductionPlanFabric");
        DataView dvPPFabric = result.Tables["ProductionPlanFabric"].DefaultView;
        //dvPPFabric.Sort = ViewState["SortExpression"].ToString();
        conn.Close();

        gvPPFabric.DataSource = dvPPFabric;
        gvPPFabric.DataBind();
    }

1 个答案:

答案 0 :(得分:0)

我在代码中看不到任何内容告诉程序刷新gridview。你可以做以下两件事之一:

  1. 如果您的更新成功> if =
  2. SqlDataAdapter RowUpdated 事件添加事件处理程序,您可以在其中调用 displayPendingFabric()方法或刷新GridView: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.rowupdated(v=vs.110).aspx