文章分类 | 推荐文章 | 最新文章 | 热点文章 | 最新软件 | 精品软件 | 下载排行 | 推荐下载 | WPS | 杀毒软件
清风网络
首 页 软件下载 网络学院
QQ 电脑入门 游戏 操作系统 图形处理 办公软件 媒体动画 精文荟萃 工具软件 网络编程 程序开发 网络技术 认证考试 网站建设 文章专栏
当前位置:清风网络网络编程Asp.NetDataGrid常见关注问题解决方案
精品推荐
特别推荐
·理解掌握ASP.NET与客户端缓存之HTTP协议
·技巧实例:ASP.NET生成静态页面实现方法
·ASP.NET、JSP及PHP之间的抉择
·.net基础知识错误注意二十二点知识
·asp.net2.0学习历程 菜鸟到中级程序员的飞跃
·.NET基础知识-什么是.NET
·初学C#+ASP.NET+Oracle时积累的备忘点滴
·专家详解:复杂表达式的执行步骤
·asp.net中的加密方法
·DataGrid常见关注问题解决方案
热点TOP10
·病毒及流氓软件自我复制的简单实现(C#)
·常见.Net 英文专业词汇收集
·打造一个通用ASP.NET数据分页控件
·初学解惑:关于ASP.NET技术的学习顺序问题
·VB.NET 与 XML 的实例操作
·ASP.NET:Repeater控件的详解
·C#网络应用编程基础练习题与答案(八)
·DataList分页、增加、删除、修改实例
·理解掌握ASP.NET与客户端缓存之HTTP协议
·探讨ASP.NET 2.0中的Web控件改进技术

DataGrid常见关注问题解决方案

日期:2007年7月15日 作者:清风网络学院 查看:[大字体 中字体 小字体]


' Visual Basic
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Me.IsPostBack Then
DsBooks1 = CType(Session("DsBooks"), dsBooks)
Else
Me.SqlDataAdapter1.Fill(Me.DsBooks1)
Session("DsBooks") = DsBooks1
DataGrid1.DataBind()
End If
End Sub

// C#
private void Page_Load(object sender, System.EventArgs e)
{
if(this.IsPostBack)
{
dsBooks1 = (dsBooks) Session["DsBooks"];
}
else
{
this.sqlDataAdapter1.Fill(this.dsBooks1);
Session["DsBooks"] = dsBooks1;
this.DataGrid1.DataBind();
}
}
For information about maintaining state, see Web Forms State Management in the Visual Studio documentation.

You can update the record normally. For an example, see Walkthrough: Using a DataGrid Web Control to Read and Write Data in the Visual Studio documentation. After updating the dataset, update the database, then refresh the dataset. Be sure to save the refreshed dataset to Session state again. Here is an example of an update handler:

' Visual Basic
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
Handles DataGrid1.UpdateCommand
Dim dr As Dataset.BooksRow
'Get a reference to row zero (where the row was inserted)
dr = Me.DsBooks1.Books(0)
Dim tb As TextBox = CType(e.Item.Cells(2).Controls(0), TextBox)
dr.title = tb.Text
Dim cb As CheckBox = CType(e.Item.Cells(3).Controls(1), CheckBox)
dr.instock = cb.Checked
Me.SqlDataAdapter1.Update(Me.DsBooks1)
DataGrid1.EditItemIndex = -1
'Refresh the dataset from the database
DsBooks1.Clear()
Me.SqlDataAdapter1.Fill(Me.DsBooks1)
'Save the refreshed dataset in Session state agin
Session("DsBooks") = DsBooks1
DataGrid1.DataBind()
End Sub

// C#
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
dsBooks.BooksRow dr;
//Get a reference to row zero (where the row was inserted)
dr = this.dsBooks1.Books[0];
TextBox tb1 = (TextBox) e.Item.Cells[2].Controls[0];
dr.title = tb1.Text;
CheckBox cb = (CheckBox) e.Item.Cells[3].Controls[1];
dr.instock = cb.Checked;
this.sqlDataAdapter1.Update(this.dsBooks1);
DataGrid1.EditItemIndex = -1;
//Refresh the dataset from the database
dsBooks1.Clear();
this.sqlDataAdapter1.Fill(this.dsBooks1);

上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] 下一页 




上一篇:微软停止WU V4 beta,力推WU V5

下一篇:无组件上传类的源代码
相关文章:
·[综合]召唤兽常见技能资质表(最新修补完整版)
·不用重装XP系统就可以解决全部故障
·XP系统运行慢?小编自用7招解决
·常见局域网的类型--局域网知识
·解决与HTTP 500 – 内部服务器错误错误信息有关的问题
·0X000000该内存不能为read的解决方法
·笔记本电脑无线上网解决方案大比拼
·用活动硬盘替代光盘?优势与问题并存
·经典常见计算机密码破解实用手册
·“性问题”女人大招供
相关软件:

特别声明:本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
[打印本页] [关闭窗口] 转载请注明来源:http://www.vipcn.net
| 帮助(?) | 版权声明 | 友情连接 | 关于我们 | 信息发布
Copyright 2007 www.vipcn.net All Rights Reserved. 鄂ICP备05000083号Powered by:viphot