Click here to Skip to main content
15,885,890 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I have a gridview. In the edit item template of gridview i placed an dropdownlist.Te dropdownlist contains the status. While updating the grid view we should check the staus of the drop down. if the status is Replaced with FSPL Inventory And send to vendor then we have to check the database FSPL Inventory whether the product name present in the database or not. If Asset_type is null then it should display Item does not Exists in FSPL Inventory. otherwise update the database with status FSPL Inventory and sent to vendor. I have written the code for it as follows. but my issue is in the grid view when if session is not null for one asset type then it is updating the status for all asset type.

C#
protected void GridView3_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {

        int rowIndex = e.RowIndex;
        Label ID = (Label)GridView3.Rows[e.RowIndex].FindControl("Label4");
        int lblID = Convert.ToInt32(ID.Text);
        Session["ID"] = lblID;
        Label Product_Name = (Label)GridView3.Rows[e.RowIndex].FindControl("Label1");
        Session["P_Name"] = Product_Name.Text;
        DropDownList ddlStatus_edit = (DropDownList)GridView3.Rows[e.RowIndex].FindControl("DropDownList7");
        string StatusName = ddlStatus_edit.SelectedItem.Value;
       


        Session["Status1"] = StatusName;


        if (ddlStatus_edit.SelectedItem.Value != "Under Repair" && ddlStatus_edit.SelectedItem.Value != "Warranty Under Repair" && ddlStatus_edit.SelectedItem.Value != "Replaced with FSPL Inventory and send to vendor")
        {
            try
            {
                con.Open();
                string qry = "Update Product_Details set Status='" + StatusName + "', [GatePass Status]= 'Close' where ID='" + lblID + "'";
                SqlCommand cmd = new SqlCommand(qry, con);
                cmd.ExecuteNonQuery();
                con.Close();
                GridView3.EditIndex = -1;
                populate();
            }
            catch (Exception ex)
            {
            }

            //else
            //  {

            //  ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('FSPL Inventory doesn't have this Asset ');", true);
        }
        //  }
        if (ddlStatus_edit.SelectedValue == "Replaced with FSPL Inventory and send to vendor")
        {
            con.Open();
            using (SqlCommand comm = new SqlCommand("select [Asset_Type] from FSPL_Inventory where Asset_Type=@Asset_Type", con))
            {
                //string Role = (string)(Session["Role"]);
                // 2. define parameters used in command object
                SqlParameter para = null;
                para = new SqlParameter();
                para.ParameterName = "@Asset_Type";
                para.Value = Product_Name.Text;
                comm.Parameters.Add(para);


                SqlDataReader reade = comm.ExecuteReader();
                while (reade.Read())
                {
                    Session["Asset_Type"] = Convert.ToString(reade["Asset_Type"]);
                }
                con.Close();
            }
        }
        if (Session["Asset_Type"].ToString() == null )
                
                    // ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('FSPL Inventory doesn't have this Asset ');", true);
                    Response.Write("<script>alert('Item does not Exists in FSPL Inventory')</script>");

                
                else
                {
                    con.Open();
                    string qry = "Update Product_Details set Status='" + ddlStatus_edit.SelectedValue + "', [GatePass Status]= 'Close' where ID='" + ID.Text + "'";
                    SqlCommand cmd = new SqlCommand(qry, con);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    GridView3.EditIndex = -1;
                    populate();
                }
            
        
  
    }
Posted
Updated 17-Aug-14 23:19pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900