- 热门文章:
- · 使用net classes访问其他网站内容
- · 在asp.net中调用Excel 文件
- · 如何利用RowFilter 属性从一个dataset中创建两个不同的datagrid
- · 使用.NET访问Internet(5) Paul_Ni(原作)(补充)
- · 使用.NET访问Internet(5) Paul_Ni(原作)
- · 使用.NET访问Internet(4) Paul_Ni(原作)(补充)
- · 使用.NET访问 Internet(3) Paul_Ni(原作)
- · 使用.NET访问Internet(4) Paul_Ni(原作)
- · 使用.NET访问 Internet(2) Paul_Ni(原作)
- · 修改后的Whois查询程序
- · 使用.NET访问 Internet(1) Paul_Ni(原作)
- · 如何取得动态装载的WEB CONTROL的属性值?
将xml作为DataGrid 操作(Sort, Edit, Delete)
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Data" %>
<html>
<script language="VB" runat="server">
Sub Page_Load(Src As Object, E As EventArgs)
If Not (IsPostBack)
DataLoad("isbn")
End If
End Sub
Sub DataLoad(parmsort as string)
Dim ds As New DataSet
Dim FS As New FileStream(Server.MapPath("books.xml"), FileMode.Open)
ds.ReadXml(FS)
MyDataGrid.DataSource = new DataView(ds.Tables(0))
MyDataGrid.DataBind()
FS.close()
END SUB
Sub DataSort(Src As Object, E As DataGridSortCommandEventArgs)
@# Bug if we sort, then Edit Item Becomes Wrong
IF MyDataGrid.EditItemIndex=-1 THEN
DataLoad(e.sortexpression)
ELSE
response.write ("Can@#t sort until editing is done!")
END IF
End Sub
Sub DataDelete(Sender As Object, E As DataGridCommandEventArgs)
DIM deletekey as string
IF MyDataGrid.EditItemIndex=-1 THEN
deletekey=MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
response.write ("deleted " & deletekey)
ELSE
response.write ("Can@#t delete until editing is done!")
END IF
END SUB
Sub DataEdit(Sender As Object, E As DataGridCommandEventArgs)
DIM editkey as string
MyDataGrid.EditItemIndex = Cint(E.Item.ItemIndex)
editkey=MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
@#response.write ("To Be Edited" & editkey)
DataLoad("")
End Sub
Sub DataCancel(Sender As Object, E As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = -1
response.write ("edit was cancelled")
DataLoad("")
End Sub
Sub DataUpdate(Sender As Object, E As DataGridCommandEventArgs)
DIM editkey as string
MyDataGrid.EditItemIndex = -1
editkey = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
response.write ("To Be Updated " & editkey)
DataLoad("")
@# howmanycols = E.Item.Cells.Count
End Sub
</script>
<body>
<h3><font face="Verdana">The Best Books Ever</font>
<span runat="server" id="MySpan"/></h3>
<form runat="server">
<ASP:DataGrid id="MyDataGrid" runat="server"
AllowSorting="true"
OnSortCommand="DataSort"
OnDeleteCommand="DataDelete"
OnEditCommand="DataEdit"
OnCancelCommand="DataCancel"
OnUpdateCommand="DataUpdate"
DataKeyField="isbn"
Width="100%"
BackColor="white"
BorderColor="black"
ShowFooter="false"
CellPadding=3
CellSpacing="0"
Font-Name="Verdana"
Font-Size="8pt"
Headerstyle-BackColor="lightblue"
Headerstyle-Font-Size="10pt"
Headerstyle-Font-Style="bold"
MaintainState="true"
>
<Columns>
<asp:ButtonColumn Text="Delete Book" CommandName="Delete"/>
<asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" ItemStyle-Wrap="false"/>
</columns>
</ASP:DataGrid>
</form>
</body>
</html>
xml的源文件:
<books>
<book>
<isbn>0070653623</isbn>
<author>Jack Trout, Steve Rivkin</author>
<title>The Power of Simplicity</title>
<category>selfhelp</category>
<comments>A Real Fun Read</comments>
</book>
<book>
<isbn>0887306667</isbn>
<author>Al Reiss, Jack Trout</author>
<title>22 Immutable Laws of Marketing</title>
<category>marketing</category>
<comments>This team offers more profound advice about creating world class marketing campaigns that will be viable for a hundred years.</comments>
</book>
<book>
<isbn>0887309372</isbn>
<author>Al Reiss, Laura Reiss</author>
<title>22 Immutable Laws of Branding</title>
<category>marketing</category>
<comments>This book is great for people who used 22 Immutable Laws of Marketing to build a brand and now want to strengthen that brand.</comments>
</book>
<book>
<isbn>0679757651</isbn>
<author>Tom Peters</author>
<title>Circle of Innovation</title>
<category>marketing</category>
<comments>His most recent book is his best by far!</comments>
</book>
<book>
<isbn>0884270610</isbn>
<author>Eli Goldthrait</author>
<title>The Goal</title>
<category>management</category>
<comments>Advocate of Theory of Constraints as applied to managment and optimization.</comments>
</book>
<book>
<isbn>068485600X</isbn>
<author>Jeff Cox, Howard Stevens</author>
<title>Selling the Wheel</title>
<category>management</category>
<comments>Excellent Treatise/Novel on the entire Sales Cycle</comments>
</book>
<book>
<isbn>0672316498</isbn>
<author>Alan Cooper</author>
<title>The Inmates Are Running The Asylum</title>
<category>management</category>
<comments>The father of Visual Basic and creator of the new art of Interaction Design - very valuable in designing websites. Basically the worlds most cutting edge thinker in User Interface design aimed at simplifying software use.</comments>
</book>
</books>
下一篇:使用net classes访问其他网站内容 >>
相关文章:
- · POP3 Client as a C# Class(转自CodeProject)
- · 饼图的一种画法(转载自aspcool)
- · 精品:Asp3.0中email有效性验证
- · 使用Div加速页面的显示(原创)
- · Creating DataGrid Templated Columns Dynamically - Part I(转自Dotnettips)
- · 关于asp.net的代码重用
- · Getting Datagrid Columns Keypress,Keyup, Keydown and other events to Fire(一个很好的东西)
- · runat=server
- · 关于上下文(Context)/2(转MS)
- · 关于上下文(Context)/1(转MS)
- · 在.NET中使用静态变量来代替Application变量
- · ASP.NET窗体对话框的实现
- · 用.NET创建定时缓存
- · 将Session值储存于SQL Server中
- · ASP.NET中的事务处理和异常处理
- · ASP.NET Caching /2
- · 嘿,懒鬼!!其实MSDN阐述得真得不错哎,不知道你从哪来的资料
- · ASP.NET Caching /1
- · 绝对酷,如何解决asp.net中javascript脚本的问题(使用服务器控件执行客户端脚本)
- · 最佳ASP.NET编程习惯
- · 一次同时上传多个文件
- · 在datagrid中求和(vb.net,c#)
- · ASP.NET中利用SQLXML WEB服务访问XML数据(转)
- · 在DataGrid中经弹出窗口确认后执行操作(删除)。(附在DataGrid中修改,添加记录)详见代码!!
- · 在datagrid中放入一个DropDownList(忘了这个问题在那里看到的了CSDN or There)
- · 简单的动态加载用户控件的方法
- · 关于如何 确认删除的另外一个办法。
- · 掉掉注意了,如何动态加载用户控件(ascx)
- · 给大家一个新的加密方法,C#的。(国外的,只用于学习,支持中文)
- · TO feixr,DataGrid中的Radiobutton
- · 微软.NET战略和ASP.NET简介(1)
- · 微软.NET战略和ASP.NET简介(3)
- · 微软.NET战略和ASP.NET简介(2)
- · 验证控件介绍--RegularExpressionValidator
- · 验证控件介绍--RangeValidator
- · 验证控件介绍--CompareValidator
- · 验证控件介绍--RequiredFieldValidator
- · 解决分页的例子。使用DataSet绑定到DataList实现的。数据库使用我刚才贴的这个。
