将datalist中的选中的数据插入数据库

来源:互联网 发布:mac finder搜索快捷键 编辑:程序博客网 时间:2024/06/10 03:50
 protected void button_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < DataList1.Items.Count; i++)
            {
                CheckBox chksel = (CheckBox)DataList1.Items[i].FindControl("selected");
                if (chksel != null)
                {
                    if (chksel.Checked)
                    {
                      
                        string users = ((Label)DataList1.Items[i].FindControl("users")).Text;
                        string dept = ((Label)DataList1.Items[i].FindControl("dept")).Text;
                        string post = ((Label)DataList1.Items[i].FindControl("post")).Text;

                        sql.ExecuteDataset("insert into addnightsalary (users,dept,post,salary,date,days,salarys,mark)values('"+users+"','"+dept+"','"+post+"','"+TextBox3.Text+"','"+TextBox6.Text+"','"+TextBox4.Text+"','"+TextBox5.Text+"','"+TextBox7.Text+"')", "a");
                    }
                }

            }


        }
0 0
原创粉丝点击