簡體   English   中英

為什么我的值沒有在gridview中更新?

[英]Why doesn't my value get updated in gridview?

我有一個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 Web表單中的按鈕代碼

    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();
    }

我在您的代碼中看不到任何內容告訴程序刷新gridview。 您可以執行以下兩項操作之一:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM