Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
this code is working other system visual studio but my system is not working

C#
protected void Button1_Click1(object sender, EventArgs e)
{
    foreach (GridViewRow gdv in GridView1.Rows)
    {
        CheckBox chk = (gdv.Cells[0].FindControl("chkbox1") as CheckBox);

        if (chk.Checked == true)
        {
            var Label = gdv.Cells[0].FindControl("lblid") as Label;
            SqlConnection cn = new SqlConnection(constr);
            SqlCommand cmd = new SqlCommand("Delete from tbl_login where Id=@Id", cn);
            cmd.Parameters.AddWithValue("@Id", int.Parse(Label.Text));
            cn.Open();
            int id = cmd.ExecuteNonQuery();
            cn.Close();

            Gridviewdetail();
        }

    }
}

this code is my system is not working
checkBox checked is always so 'False' why
checkBok Checked is not show 'true'
if another idea about delete row on checkBox Check so plz help me. only button event

What I have tried:

plz help me sir
why show always false checkbox checked
Posted
Updated 28-Apr-17 21:36pm
v4
Comments
Andy Lanng 26-Apr-17 11:24am    
not true. it reads from the first cell on each row. read the code again (I too hate ints in code and always have the knee jerk reaction that that is where the flaw is).
BTW: how many "that"'s can you fit into a sentence in a row (hint: the record is 15)
Andy Lanng 26-Apr-17 11:37am    
I wrote the word "that" on a board
I guy called That wrote the word "that" on a board:
"I saw that 'that' that That wrote".
Now the word has lost all meaning to me
Bryian Tan 26-Apr-17 11:48am    
I misread :(
Andy Lanng 26-Apr-17 11:53am    
Misread is understandable. Misunderstood is an issue. Admitting either is admirable. further understanding is learn-able and achievable. Buy Coke
Oh s*&t got into slogans again :P
Andy Lanng 26-Apr-17 11:21am    
ur my guurd. I hate seeing static ints, but here it's fine.
The issue must be in when the function is called.

Button1 click does not update the form. it acts on it. I feel that the issue is that buton1 does not submit the form so (asp?) server side does not see the change. Can you confirm this?

 
Share this answer
 
There are lots of answer available on google.
Here is some references

Link 1


Link 2


Link 3

Better to spend some time to understand code logic.
 
Share this answer
 
Comments
Member 10506503 29-Apr-17 4:05am    
ok sir

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