Click here to Skip to main content
16,009,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void btnSave_Click(object sender, EventArgs e)
        {
            int id = 0;
            string strname = string.Empty;
            int Phone_Number = 0;
            string Address = string.Empty;
            for (int i = 0; i <grd_Data.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)grd_Data.Rows[i].Cells[1].FindControl("chkSelecct");
                if (chk.Checked)
                {
                  //  id = Convert.ToInt32(grd_Data.Rows[i].Cells[1].Text);
                    strname = grd_Data.Rows[i].Cells[1].Text;
                 //   Phone_Number = Convert.ToInt32(grd_Data.Rows[i].Cells[3].ToString());
                    Address = grd_Data.Rows[i].Cells[3].Text.ToString();

                    SqlConnection con = new SqlConnection(CS);
                    con.Open();
                    string insertquery="insert into tblCheck(name,phone,address) values(@name,@phone,@address)";
                    SqlCommand cmd = new SqlCommand(insertquery,con);
                    cmd.Parameters.AddWithValue("@name", strname);
                    cmd.Parameters.AddWithValue("@phone", Phone_Number);
                    cmd.Parameters.AddWithValue("@address", Address);
                    cmd.ExecuteNonQuery();
                    con.Close();
                    
                }
            }         


What I have tried:

Data is coming properly but value is not inserting to database.
Posted
Updated 13-Aug-16 3:06am
Comments
Karthik_Mahalingam 12-Aug-16 23:58pm    
are you getting any error message?

1 solution

for(int i=0;i<datagrid1.rows.count-1;i++)>
{
//Datagridview Check box column is not empty
if(datagrid1.Rows[i].Cells[0].Value!=null)
{
//Checkbox checked or not
bool a=(bool)datagrid1.Rows[i].Cells[0].Value;

//Check box is checked then this code is execute
if(a==true)
{
// Your Coding here...
}
}
}
 
Share this answer
 
Comments
Adityakumar2318 20-Aug-16 4:37am    
Thank you, my question is solved.
SDK Channel 27-Jul-20 6:53am    
how to explain your code in vb.net?

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