我爱Aspx >> Asp.Net >> 使用 ASP+ DataGrid 控件来创建主视图/详细资料视图 (2)
使用 ASP+ DataGrid 控件来创建主视图/详细资料视图 (2)
- :未知 Դ:internet :2007-5-5 19:43:51 ؼ:asp
- 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
Ҷƪл˵?
- һƪAlpha 闪烁效果
һƪ使用 ASP+ DataGrid 控件来创建主视图/详细资料视图
- 关于我们 | 广告服务 | 网站建设 | 版权申明 | 申请链接 | 联系我们
- Copyright © 2007 5iaspx.COM. All Right Reserved.
- 本站内容仅供学习,研究,探讨,个人收藏,如有侵权,敬请联系我们,我们尽快解决!