将xml作为DataGrid 操作(Sort, Edit, Delete)
来源:互联网 发布:java培训费用要多少 编辑:程序博客网 时间:2024/05/21 06:15
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<%@ 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>
</book
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
我们将显示如何将一个xml文件作为DataGrid,这样对其的排序,编辑,等操作将是非常简单的事。<%@ 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>
</book
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 将xml作为DataGrid 操作(Sort, Edit, Delete)
- 给初学的朋友们,datagrid用xml作为数据源,并且有更新,删除和排序的操作(VB)
- Perform the Edit//Cancel//Update//Delete function of the DataGrid.
- 将Recordset作为XML保存
- 内表操作-insert,delete,modify,sort
- 在DataGrid的每一行中用图片的形式显示Edit和Delete的功能
- 将XML数据读入DataGrid中
- WPF - 使用XML作为datagrid数据源进行binding
- about Flex DataGrid edit
- Asp.net中如何将DataSet写入xml文件,及如何将xml读出来绑定到DataGrid(原创)
- EDIT操作
- Ctools add/edit/delete node
- jquery easyui datagrid subgrid edit
- DataGrid Delete Command Confirm
- C#中怎么将XML作为参数post到接口
- Datagrid sort 排序
- php对图书的增删改查操作(xml作为数据存储机制)
- 操作DataGrid单元格(TESTED)
- 如何使用动态共享对象的模式来安装PHP
- Creating DataGrid Templated Columns Dynamically -
- 关于Zend Optimizer
- 如何取得动态装载的WEB CONTROL的属性值?
- 定制php4的session功能
- 将xml作为DataGrid 操作(Sort, Edit, Delete)
- 把PHP4安装到Win2000的IIS5中
- 使用.NET访问Internet(5) Paul_Ni(原作)
- ZendCache:让网站飞起来
- 使用.NET访问Internet(4) Paul_Ni(原作)(补充)
- PHP网站提速三大软招
- 使用.NET访问 Internet(3) Paul_Ni(原作)
- PHP4.04在英文win2000下的安装
- 使用.NET访问Internet(4) Paul_Ni(原作)