国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > XML > 正文

將xml作為DataGrid 操作(Sort, Edit, delete)

2024-09-05 20:55:44
字體:
來源:轉載
供稿:網友

我們將顯示如何將一個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>
    
</books>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 淮安市| 仁寿县| 木里| 黔南| 兴国县| 霍城县| 鄯善县| 怀柔区| 澄江县| 墨玉县| 子长县| 合作市| 尼勒克县| 淮南市| 固安县| 偏关县| 政和县| 巴林右旗| 囊谦县| 凤阳县| 塔城市| 松原市| 思南县| 永安市| 商城县| 长阳| 江源县| 淄博市| 开江县| 屏山县| 尼玛县| 邯郸市| 包头市| 西和县| 政和县| 会泽县| 布尔津县| 阳东县| 安塞县| 南京市| 同德县|