带有datagridview的按钮 [英] button with datagridview

查看:66
本文介绍了带有datagridview的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在datagridview的第一栏中有一个按钮.每当我单击datagridview中的按钮时,我想删除该行plz给出一个想法

I have a button in the first column of the datagridview. Whenever I click on the button in the datagridview, i want to delete that row plz give an idea

推荐答案

将该按钮的命令名称设置为"Delete",然后检查datagrid的rowcommand属性中的命令名称,并在那里执行delete操作和bindgrid操作,以便删除该记录后的网格将被更新...

也不要忘记将id属性设置为数据键,这样就可以在命令参数中传递它并删除想要的行.


例如..


set the command name of that button to "Delete" and then check the command name in the datagrid''s rowcommand property and perform delete operation and bindgrid operation there so the grid after deleting that record will be updated...

also dont forget to make the id property as a datakey so you can pass it in command argument and delete the row you wish to.


for eg..


protected void datagrid_RowCommand(object sender, GridViewCommandEventArgs e)
       {
           try
           {
               if (e.CommandName == "Delete")
               {
                   int Args = Convert.ToInt32(e.CommandArgument);
                   string _id = grddisplayrequest.DataKeys[Args]["ID"].ToString();

/* Perform Delete operation here */
/* bind grid operation here */
               }
           }
           catch (Exception ex)
           {
               Response.Write(ex.Message);
           }
       }
   }




希望对您有所帮助.

如果此答案对您有帮助,请投票. :)




I hope this helped you.

Please give vote if this answer helped you. :)


这篇关于带有datagridview的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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