更新按钮中的多行单击plz hlp me [英] update multiple row in button click plz hlp me

查看:60
本文介绍了更新按钮中的多行单击plz hlp me的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void update_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
          
            GridViewRow row = GridView1.Rows[i];
            CheckBox chk = (CheckBox)row.FindControl("CheckBox1");
            GridView1.EditIndex = i;
            if (chk.Checked)
            {
                TextBox nam = (TextBox)GridView1.Rows[i].FindControl("TextBox1");
                DropDownList gen = (DropDownList)row.FindControl("DropDownList1");
                DropDownList qua = (DropDownList)row.FindControl("DropDownList2");
                
                SqlCommand cmd = new SqlCommand("update registration set username=@username,gender=@gender,qualification=@qualification where id=@id", con);
                cmd.Parameters.AddWithValue("@username", nam.Text);
                cmd.Parameters.AddWithValue("@gender", gen.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@qualification", qua.SelectedItem.Text);
                cmd.Parameters.AddWithValue("@id", id);
                cmd.ExecuteNonQuery();
                con.Close();
            }
            
        }
    }

推荐答案

这篇关于更新按钮中的多行单击plz hlp me的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆