Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i done with approve/reject documents but there is a problem

suppose there is a 3 documents in grid view when admin login and want to approve/reject only 1 document i.e docid 81 and click on submit button then data save in database

approval table
SQL
**seqno docid approveid  approveby**
79     14      3       john
80     16      3       john
81     17      2      john


but in my code when admin approve/reject only 1 (i.e 81 docid) document whereas admin not worked in others two then admin click on submit button then other two documents data are also save in approval (i.e 79,80 docid)table ..why this happened?

here is submit button code

C#
protected void Button1_Click(object sender, EventArgs e)
    {

        string connStr = 
        ConfigurationManager.ConnectionStrings["mydms"].ConnectionString;
        SqlConnection mySQLconnection = new SqlConnection(connStr);
        if (mySQLconnection.State == ConnectionState.Closed)
        {
            mySQLconnection.Open();
        }

        foreach (GridViewRow row in GrdFileApprove.Rows)
        {

            if (row.RowType == DataControlRowType.DataRow)
            {
                DropDownList DropDownListcontrol = row.FindControl("DropDownList4") as
             DropDownList;
                SqlCommand cmd = new SqlCommand("approveddd", mySQLconnection);
                cmd.CommandType = CommandType.StoredProcedure;                
                cmd.Parameters.Add("@DocID", SqlDbType.Int).Value = 
              Convert.ToInt32((row.Cells[1].Text));
                cmd.Parameters.Add("@ApproveID", SqlDbType.Int).Value = 
               Convert.ToInt32(DropDownListcontrol.SelectedValue);
                cmd.Parameters.Add("@ApproveBy", SqlDbType.VarChar, 50).Value = 
               (Session["Login2"]);
                cmd.ExecuteNonQuery();
                DMSLIB.Doc myDoc = new DMSLIB.Doc();
                myDoc.MarkDocAs(Convert.ToInt16(row.Cells[1].Text), Convert.ToInt32(DropDownListcontrol.SelectedValue));


            }
            else
            {
                apfi.Text = "Error";
            }
        }


        if (mySQLconnection.State == ConnectionState.Open)
        {
            mySQLconnection.Close();
        }
Posted
Updated 4-Nov-13 21:35pm
v2
Comments
[no name] 5-Nov-13 5:39am    
81 is the docid or seqno ?
Diya Ayesa 5-Nov-13 10:32am    
docid

1 solution

Hi,

You may use a gridview option rather using an individual Button for this functionality.

Option 1:
In Gridview, you have a option to add the [Command Type -> Button Controls]
Button will be available on each Row and which ever button you click the event will be generated and that can be handled in code Behind to your specific operations.

Find sample application here.

Row updating event in gridview ASP.NET[^]


Option 2:
You can add a Check box control for each Row, finally when you click Submit Button, then as you are doing you can check each row of grid, and update Databse only the Check box status is checked else discard.
Note: If you have 1000+ rows, in this approach all the rows needs to be traversed which is not optimal.

Thanks!
 
Share this answer
 
v2
Comments
Diya Ayesa 5-Nov-13 10:49am    
i use dropdown in gridview
Diya Ayesa 6-Nov-13 3:36am    
????????

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