Rowshan Ali

Rowshan Ali

  • NA
  • 64
  • 143.2k

Insert data from gridview by check.

Feb 20 2013 3:30 AM
Hi dear
i am in problem to insert data from gridview by checking checkbox
i give my try below  & source in zip file

IDnamwqtyamountSelect
73ras44.0000
1920ras44.0000
1921ras44.0000
1922ras44.0000
1923ras44.0000
1961ras44.0000

  

protected void Page_Load(object sender, EventArgs e)
        {
            var st = from s in db.ITEMMs select s;
            gvw_employees.DataSource = st;
            gvw_employees.DataBind();
        }
        DataClasses1DataContext db = new DataClasses1DataContext();

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                 //foreach (GridViewRow dg in gvw_employees.Rows)
                 //           {
                 //               CheckBox ckbox;
                 //               ckbox = ((CheckBox)dg.FindControl("checkBox"));
                 //               if (ckbox.Checked == true)
                 //               {

                                    for (int i = 0; i < gvw_employees.Rows.Count; i++)
                                    {


                                        int Id = Convert.ToInt32(gvw_employees.Rows[i].Cells[0].Text);

                                        string name = gvw_employees.Rows[i].Cells[1].Text;
                                        int qty = Convert.ToInt32(gvw_employees.Rows[i].Cells[2].Text);
                                        decimal amt = Convert.ToDecimal(gvw_employees.Rows[i].Cells[3].Text);
                                        var st = new ITEMM
                                        {
                                            ID = Id,
                                            namw = name.ToString(),
                                            qty = qty,
                                            amount = amt,

                                        };
                                        db.ITEMMs.InsertOnSubmit(st);
                                        db.SubmitChanges();
                                        Label1.Text = "success";
                                    }
                                //}
                                //else
                                //{
                                //    Label1.Text = "faiels";
                                //}

                   
                //}
            }
            catch (Exception ex)
            {
                Label1.Text = ex.Message.ToString();
            }
        }

if any one help me that great..

Attachment: sent.zip

Answers (1)