我如何在不单击保存的情况下将数据保存在datagrid中 [英] how can i save data in datagrid without clicking save

查看:75
本文介绍了我如何在不单击保存的情况下将数据保存在datagrid中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有这个问题,希望我能帮助我,
当我从一个单元格移动到另一个单元格时,如何直接更改保存在数据库中的数据网格
例如..我有一个包含名称和电话号码的数据网格...当我更改电话号码并转到其他单元格时,无需单击保存按钮即可保存更改.

Hi all,,
i have this question ,,i hope u can help me ,,
How to make changes in the datagrid kept in the database directly when i move from one cell to another
For example .. I have a Data Grid which contains the name and phone number ... When i change the phone number and move on to other cell change is saved without clicking on the Save button.

推荐答案

您可以通过设置一些属性并实现所使用控件的事件来做到这一点.例如,如果您使用的是文本框,则将其AutoPostBack属性设置为true,如

You can do this by setting some properties and implementing the events of the control you are using. For example, if you are using a textbox then set its AutoPostBack property to true as

AutoPostBack="true"



并将其onTextChanged事件实现为



and implement its onTextChanged event as

ontextchanged="txtTest_TextChanged"





protected void txtTest_TextChanged(object sender, EventArgs e)
    {
// Write your code to save values in database.
    }



或者,您也可以使用ajax并使用客户端onblur事件异步保存数据.



Alternatively you can also use ajax and save your data asynchronously using client side onblur event.


您需要使用单元格更改事件:MSDN:DataGrid.CurrentCellChanged事件 [ MSDN:UIElement.GotFocus事件 [^ ]

每次您在datagrid单元中更改值(或单元针对getFocus事件进行聚焦)时,都会引发此事件.您可以在此事件中保存数据.因此,无需单击保存就可以保存数据.
You need to use cell change event: MSDN: DataGrid.CurrentCellChanged Event[^]
You can also use, cell focus event: MSDN: UIElement.GotFocus Event[^]

Every time you change value in the datagrid cell (or cell is focused for gotFocus event), this event will be raised. You can save your data in this event. Thus, without clicking save you will be able to save data.


这篇关于我如何在不单击保存的情况下将数据保存在datagrid中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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