Click here to Skip to main content
15,179,684 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Can someone please tell me whats wrong in my code? The below is my C# code that i tried..
C#
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();        
}
Posted
Updated 24-Sep-13 8:21am
v3
Comments
[no name] 24-Sep-13 11:34am
   
Unless you have only one record in your database table you need a WHERE clause for your UPDATE. Debug your code and see if your queries are even running.

1 solution

Probably rbpApprove and rbpReject can not be checked in the same time...

Have a look at below table and your code:

rbpApprove.Checked  rbpReject.Checked  Result  
truetruetrue
truefalsefalse
falsetruetrue
falsefalsefalse


Do you know what to check in if statement, now?
   

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