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

首頁(yè) > 開發(fā) > 綜合 > 正文

實(shí)現(xiàn)動(dòng)態(tài)建立DataList模版

2024-07-21 02:22:56
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
為這個(gè)頭痛了有一段時(shí)間了。嘗試過(guò)一些方法也問(wèn)了一些人查看了一些文檔。終于功夫不負(fù)有心人,得出了一種比較簡(jiǎn)便清楚的方法。首先要實(shí)現(xiàn)itemplate接口,建立了一個(gè)基類相關(guān)代碼如下:public class basetemplate implements itemplate protected templatetype as listitemtype '模版的種類 protected pnlmain as panel '建立主面板 sub new(byval type as listitemtype) me.templatetype = type end sub sub instantiatein(byval container as control) implements itemplate.instantiatein me.pnlmain = new panel select case templatetype case listitemtype.header addhandler me.pnlmain.databinding, addressof me.headertbinding case listitemtype.item addhandler me.pnlmain.databinding, addressof me.itemtbinding case listitemtype.alternatingitem addhandler me.pnlmain.databinding, addressof me.alternatingitemtbinding case listitemtype.footer addhandler me.pnlmain.databinding, addressof me.footertbinding end select container.controls.add(me.pnlmain) end sub '數(shù)據(jù)item protected overridable sub itemtbinding(byval sender as object, byval e as system.eventargs) end sub '頭item protected overridable sub headertbinding(byval sender as object, byval e as system.eventargs) end sub '交替item protected overridable sub alternatingitemtbinding(byval sender as object, byval e as system.eventargs) end sub '腳item protected overridable sub footertbinding(byval sender as object, byval e as system.eventargs) end sub end class不是很晦澀。通過(guò)判斷類型,為panel加載綁定事件。下面在給出一個(gè)實(shí)現(xiàn)的子類代碼:public class mytalktemplate inherits basetemplate sub new(byval type as listitemtype) mybase.new(type) end sub protected overrides sub itemtbinding(byval sender as object, byval e as system.eventargs) dim pnl as panel dim container as datalistitem pnl = ctype(sender, panel) container = ctype(pnl.namingcontainer, datalistitem) dim htbl as new htmltable htbl.width = "100%" '保證足夠?qū)?dim hrow as htmltablerow dim hcell as htmltablecell '圖片 dim img as new webcontrols.image img.height = new unit(80) '設(shè)定長(zhǎng)和寬 img.width = new unit(80) img.imageurl = string.format("{0}", container.dataitem("talkimg")) hrow = new htmltablerow hcell = new htmltablecell hcell.rowspan = 2 hcell.controls.add(img) hrow.cells.add(hcell) '主題 hcell = new htmltablecell hcell.align = "center" hcell.controls.add(new literalcontrol("<big>主題</big>")) hrow.cells.add(hcell) htbl.rows.add(hrow) hrow = new htmltablerow hcell = new htmltablecell hcell.width = "100%" '保證足夠的寬度 hcell.valign = "top" '豎直方向位于頂端 hcell.controls.add(new literalcontrol(string.format("<h5>{0}</h5>", container.dataitem("talktitle")))) hrow.cells.add(hcell) htbl.rows.add(hrow) '內(nèi)容 hrow = new htmltablerow hcell = new htmltablecell hcell.colspan = 2 hcell.height = "1" hcell.bgcolor = "#808080" hrow.cells.add(hcell) htbl.rows.add(hrow) hrow = new htmltablerow hcell = new htmltablecell hcell.colspan = 2 hcell.controls.add(new literalcontrol(string.format("{0}", container.dataitem("talktext")))) hrow.cells.add(hcell) htbl.rows.add(hrow) me.pnlmain.controls.add(htbl) end sub寫的有點(diǎn)多余哈。就是利用container.dataitem來(lái)建立各個(gè)控件。之所以不直接在實(shí)現(xiàn)接口時(shí)間直接利用綁定的信息來(lái)建立控件,是因?yàn)槭录樞颉nstantiatein這個(gè)函數(shù)在基類的綁定事件之前執(zhí)行,所以只能先添加一個(gè)panel(或其他容器控件),然后在基類綁定后,再調(diào)用panel的綁定事件。這樣就可以實(shí)現(xiàn)。在此之前我曾經(jīng)放棄使用datalist而自己寫table代碼來(lái)實(shí)現(xiàn)數(shù)據(jù)的顯示。但在交替顯示,分不同列顯示,制定樣式方面都很麻煩,所以還是推薦使用datalist動(dòng)態(tài)加載模版來(lái)按行顯示數(shù)據(jù)。不知道還有沒(méi)有更好的實(shí)現(xiàn)辦法,期待。。。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 嘉鱼县| 双流县| 满洲里市| 阜康市| 辽阳县| 阿克苏市| 溧水县| 翁源县| 辽中县| 光山县| 沧源| 措勤县| 甘泉县| 改则县| 城固县| 简阳市| 遂川县| 静安区| 青岛市| 达日县| 湘潭市| 甘洛县| 康乐县| 商河县| 芜湖县| 凭祥市| 博白县| 镇雄县| 吉林省| 大竹县| 开远市| 嘉鱼县| 垦利县| 太白县| 扶绥县| 汤阴县| 甘肃省| 金华市| 顺平县| 石台县| 淄博市|