I have data grid and I have two radio buttons in the datagrid i.e approve or reject and also one button in datagrid i.e submit

what i want to do is when approved button is selected and submit button in the datagrid is clicked for one row I want the data of that row to be stored in the database with Isactive as 1 and the row should be deleted from the datagrid, but details must be stored in the database.

Similarly when the reject button is selected and submit button in datagrid is clicked,the data of that row should be stored in the database with Isactive as 0 and the row should be deleted from the datagrid

details must be stored in the database.

The isActive is not updating in the database,I dont know hot give the Where condition for the update clause?

Can someone please tell me whats wrong in my code? The below is my C# code that i tried..

protected void submit(object sender, EventArgs e)
{
// *Get the Gridview Row* //
DataGridItem drow = (DataGridItem)(sender as Control).Parent.Parent;

RadioButton rbpApprove = (RadioButton)drow.FindControl("rbtnapprove");
RadioButton rbpReject = (RadioButton)drow.FindControl("rbtnreject");

if (rbpApprove.Checked == true)
{
conn.Open();
SqlCommand cmd = new SqlCommand("Update table set IsActive= 0 ", conn);

cmd.ExecuteNonQuery();
conn.Close(); 
}
else if (rbpReject.Checked == true)
{
conn.Open();
SqlCommand cmd = new SqlCommand("Update table set IsActive= 1", conn);
cmd.ExecuteNonQuery();
conn.Close();
}


string empid = dgi.Cells[0].Text;
string employeename = dgi.Cells[2].Text;
string designation = dgi.Cells[3].Text;

conn.Open();
SqlCommand comm = new SqlCommand("insert into [table] values (" + empid + ",'" + employeename + "','" + designation + "')", conn);
comm.ExecuteNonQuery();
conn.Close(); 
}

There is no need to do all this, you are opening and closing your connection to the db twice. Instead of this, why dont you store 'isactive' in your table row depending on which button is clicked (submit or reject).

    DataGridItem drow = (DataGridItem)(sender as Control).Parent.Parent;
    RadioButton rbpApprove = (RadioButton)drow.FindControl("rbtnapprove");
    RadioButton rbpReject = (RadioButton)drow.FindControl("rbtnreject");

    SqlCommand cmd;

    string empid = dgi.Cells[0].Text;
    string employeename = dgi.Cells[2].Text;
    string designation = dgi.Cells[3].Text;

    if (rbpApprove.Checked == true)
    {
    cmd = new SqlCommand("insert into [table] values ('" + empid + "','" +     employeename + "','" + designation + "',1)", conn);
    //see here you are inserting a 1 which will be for column 'isactive'
    }
    else if (rbpReject.Checked == true)
    {
    cmd = new SqlCommand("insert into [table] values ('" + empid + "','" + employeename + "','" + designation + "',0)",conn);
    //see here you are inserting a 0 which will be for column 'isactive'
    }

    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close(); 
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.