仅在asp.net gridview上更新选定的行 [英] UPDATE selected row only on asp.net gridview

查看:105
本文介绍了仅在asp.net gridview上更新选定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是场景(用户点击更新)

TIME IN TIME OUT

PERSON A | 7:30 8:00

PERSON A | 7:35 8:00



我有以下代码:

Here is the scenario (user clicks update)
TIME IN TIME OUT
PERSON A | 7:30 8:00
PERSON A | 7:35 8:00

I have the following code:

string cmdstr = "update dbo.RecordEmployee set TIME_OUT=@timeout, REMARKS=@editRemarks where EMPLOYEE_NAME =@empname";





它的作用以及何时更新第一条记录8:00将被分配到第一条记录,它也将被分配到第二条记录





我想在这里实现的是当用户点击时更新,A人超时的其他记录将保持为空



因此更新的唯一选定行将具有值



what it does and when I update the first record 8:00 will be assigned to the first record, and it will also be assigned to the second record


what I want to achieve here is when the user clicks update, the other record of person A's time out will remain null

so the only selected row updated will have a value

推荐答案

你需要为每一行都有一个id列,并将其作为参数传递给你的查询。

当前行id。在你的表中你可能每行都有一个唯一的id。

在网格视图中,你有编辑按钮传递commandName作为id

例如

You need to have an id column for each row and pass it as parameter in to your query.
The current row id. in your table you may have a unique id for each row.
In grid view where you are having your edit button pass commandName as id
e.g
<asp:button id="btnEdit" text="Edit" runat="server" commandargument="<%#Eval("id")%>" commandname="Edit" xmlns:asp="#unknown" />





RowCommand事件:



in grid view RowCommand event:

using(SqlCommand cmd = new SqlCommand("update dbo.RecordEmployee set TIME_OUT=@timeout, REMARKS=@editRemarks where EMPLOYEE_NAME =@empname and id=@id", conn))
        {
           cmd.Parameters.AddWithValue("@id", id);
           cmd.ExecuteNonQuery();
        }


点击这里,可能会得到任何有用的信息

链接在这里
Check here, may be you get any useful information
link here


这篇关于仅在asp.net gridview上更新选定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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