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

首頁 > 開發 > XML > 正文

給初學的朋友們,datagrid用xml作為數據源,并且有更新,刪除和排序的操作(VB)

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


收集最實用的網頁特效代碼!

<%@ 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>


by the way, here is the xml source for this example:
run this code

<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>

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 谢通门县| 英德市| 保定市| 辛集市| 墨脱县| 都江堰市| 八宿县| 门源| 读书| 金坛市| 襄汾县| 陵川县| 吕梁市| 右玉县| 万山特区| 高邑县| 兴文县| 色达县| 建瓯市| 东乌珠穆沁旗| 焦作市| 札达县| 顺昌县| 汕尾市| 双鸭山市| 武安市| 漳浦县| 淮南市| 翁源县| 石柱| 齐齐哈尔市| 陆丰市| 韶山市| 瓮安县| 台东市| 汝阳县| 行唐县| 姜堰市| 丰都县| 三台县| 平凉市|