step6page.cs:
namespace samples { ... public class step6page : page { // 更新当前选定的作者并重新加载与选定内容对应的书名 // 网格 protected void loadtitlesgrid() { updateselection(); titlesgrid.databind(); } // 处理书名网格中的 cancelcommand 事件,以 // 不施用更改就结束编辑 protected void oncancelcommandtitlesgrid(object sender, datagridcommandeventargs e) { titlesgrid.edititemindex = -1; loadtitlesgrid(); } // 处理书名网格中的 editcommand 事件,以 // 开始编辑某一行 protected void oneditcommandtitlesgrid(object sender, datagridcommandeventargs e) { titlesgrid.edititemindex = e.item.itemindex; loadtitlesgrid(); } // 处理书名网格中的 updatecommand 事件,以施用 // 所作的更改并结束编辑 protected void onupdatecommandtitlesgrid(object sender, datagridcommandeventargs e) { textbox pricetext = (textbox)e.item.findcontrol("column3control"); string newprice = pricetext.text.substring(1); dataset ds = getsessiondata(); datatable titlestable = ds.tables["title"]; string titleid = (string)titlesgrid.datakeys[e.item.itemindex]; datarow[] rows = titlestable.select("title_id = '" + titleid + "'"); datarow editrow = rows[0]; editrow.beginedit(); editrow["price"] = newprice; editrow.endedit(); editrow.acceptchanges(); titlesgrid.edititemindex = -1; loadtitlesgrid(); } }}editcommand 事件是在单击 edit 按钮时引发的。只需将 datagrid 的 edititemindex 属性设定为包含被单击按钮的项目的索引的属性。要防止编辑某一个别行,不采取任何动作就返回。另外,要继续进行编辑,就必须重新加载数据源并调用 databind。这通过调用 loadtitlesgrid 方法来完成。
您必须处理的第二个事件就是 cancelcommand 事件。这是单击 cancel 按钮时引发的。实施十分类似于前一处理器。如想结束编辑,则只需将 edititemindex 属性重置为 ?,并重新加载数据源。如果需要维持行的编辑模式,则仅需不采取任何动作就从函数返回即可。
要处理的最后一个事件就是 updatecommand 事件,这是单击 update 按钮时引发的。这里是实际工作发生的地方。从存在于项目中的控件抽取新的值,然后更新数据源。一旦将新的值使用完毕,就将 edititemindex 重置为 ?,以返回到只读模式,并连同其数据源一起重新加载控件。对于前两个事件,您可以不采取任何动作就从该函数返回,以保持该行的编辑模式状态。
这一步又再次举例说明控件中实施的显式数据绑定模型。在这一实施情形中,只在某行的状态从只读模式更改为编辑模式或相反时才需要数据源。注意, datagrid 自身并不更新其数据源。实质上,数据绑定是单向的。采用本模型的目的在于让您拥有对数据源更新的控制。在大多数典型的应用程序中,更新需要预处理,并且是由业务对象或已存储的过程来调用的。另外,单向数据绑定并不要求每个时间都有实时的数据源。
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器