如何在不使用数据源控件的情况下使用GridView中的CheckBoxes更新数据库的多行? [英] How to update multiple rows of database using CheckBoxes in GridView without using DataSource Controls?

查看:76
本文介绍了如何在不使用数据源控件的情况下使用GridView中的CheckBoxes更新数据库的多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.我在每行中都有一个带有CheckBoxes的GridView.现在我的要求是通过在GridView中检查它们的CheckBoxes来更新所选的行.数据源控件在这里.请Pzz帮助我解决此问题.感谢Advance.

Hi i to all.I''ve a GridView with CheckBoxes in each row.Now my requirement is to update the rows that are selected by checking against their CheckBoxes in the GridView.By the way I''m not using any DataSource Controls here.Plz help me regarding this scenario.Thanks in Advance.

推荐答案

Jagan

假设GridView的CheckBox的ID为chkDeleteUser,然后使用填充代码从GridView删除行.

Hi Jagan

Suppose ID of your CheckBox of your GridView is chkDeleteUser then use the fillowing code to delete the Rows from GridView


try
        {
             //Check for CheckBox in everyrow of Gridview
            foreach (GridViewRow row in gvDeleteUser.Rows)
            {
                CheckBox chkbox = (CheckBox)row.FindControl("chkDeleteUser");
                //Check if the CheckBox for perticular row is Checked then delete it.
                if (chkbox.Checked)
                {
                    //Fetch the Primary Key value for that Row and pass to delet eit.
                    int uid = (int)gvDeleteUser.DataKeys[row.RowIndex].Value;
                    
                    //Write here logic of the delet euser
                    //For example call the stored procedure with parameter as uid
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }

//一旦再次删除所有数据加载gridview以反映已删除的用户,
loadGriedData();
请不要忘记在网格视图中添加DataKeyName ="PrimaryKeyField"属性,如

< asp:gridview id ="Gridview1" run =服务器" datakeynames ="CustID" xmlns:asp =#unknown">

请检查一下,如有任何疑问,请通知我.

如果解决了,请确定为已解决.

//once you delete the all data load gridview again to reflect the deleted users
loadGriedData();
Please don''t forget to add the DataKeyName="PrimaryKeyField" property in the grid view like

<asp:gridview id="Gridview1" run="server" datakeynames="CustID" xmlns:asp="#unknown">

Please check it and let me know in case of any concerns.

And please make it as resolved if it resolves.


这篇关于如何在不使用数据源控件的情况下使用GridView中的CheckBoxes更新数据库的多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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