Using the Template Collection to Add a Template Column in WebDataGrid
WebDataGrid™ has a template collection to store common, reusable templates. You can add item templates to the collection using the WebDataGrid control's smart tag. You can also do this in code using the Templates collection.
You can use the templates as you would for any templatable element in WebDataGrid. The collection gives you a place to store and quickly access templates that you plan to use often.
Next I will show you how to add template column programmaticly.
1. Define your custom Tempate
Public Class CheckBoxColumnTemplate
Implements System.Web.UI.ITemplate
Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
Dim checkBox As New CheckBox()
checkBox.ID = "CheckBox1"
checkBox.Checked = False
checkBox.Attributes.Add("onclick", "selectFirstColumn(event);")
container.Controls.Add(checkBox)
End Sub
End Class
Public Class LinkButtonColumnTemplate
Implements System.Web.UI.ITemplate
Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
Dim linkButton As New LinkButton()
linkButton.ID = "LinkButton1"
container.Controls.Add(linkButton)
End Sub
End Class
2. Define a Enum for Template Type
Public Enum GridViewColumn
Text
CheckBox
LinkButton
CheckBoxWithEvent
End Enum
3. Create Template Column
Public Shared Function CreateTemplateDataField(ByVal key As String, ByVal headerText As String, ByVal width As Integer, ByVal hidden As Boolean) As TemplateDataField
Return CreateTemplateDataField(key, headerText, width, hidden, GridViewColumn.CheckBox)
End Function
Public Shared Function CreateTemplateDataField(ByVal key As String, ByVal headerText As String, ByVal width As Integer, ByVal hidden As Boolean, ByVal colType As GridViewColumn) As TemplateDataField
Dim column As New TemplateDataField()
Dim itemTemplate As System.Web.UI.ITemplate
Select Case colType
Case GridViewColumn.CheckBox
itemTemplate = New CheckBoxColumnTemplate()
Case GridViewColumn.Text
itemTemplate = New TextColumnTemplate()
Case GridViewColumn.LinkButton
itemTemplate = New LinkButtonColumnTemplate()
Case GridViewColumn.CheckBoxWithEvent
itemTemplate = New CheckBoxWithEventColumnTemplate()
Case Else
itemTemplate = New CheckBoxColumnTemplate()
End Select
column.ItemTemplate = itemTemplate
column.Key = key
column.Header.Text = headerText
column.Width = width
column.Hidden = hidden
Return column
End Function
4. Create a Bound Column
Public Shared Function CreateBoundDataField(ByVal key As String, ByVal headerText As String, ByVal width As Integer, ByVal hidden As Boolean) As BoundDataField
Dim column As New BoundDataField()
column.Key = key
column.DataFieldName = key
column.Header.Text = headerText
column.Width = width
column.Hidden = hidden
Return column
End Function
5. Put All Together
With childGrid
.Columns.Add(Common.CreateTemplateDataField("CheckBoxs", "", 20, False, GridViewColumn.CheckBox))
.Columns.Add(Common.CreateBoundDataField("ID", GlobalResources.GetString("GridHeader_ID"), 60, True))
End With
References
[@more@]來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/13651903/viewspace-1044090/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- go text/template & Consul-templateGo
- You are using the runtime-only build of Vue where the template compiler is not available.UIVueCompileAI
- ansible template
- template might not exist or might not be accessible by any of the configured Template Resolvers
- c++ 模板模板引數("Template Template Parameters")C++
- ES 筆記十四:Index Template 和 Dynamic Template筆記Index
- Vue template To JSXVueJS
- C_template
- Mendix Page Template
- go template使用Go
- template0 的 age 問題. vacuum template0
- 【雜談】Starter Template
- 模板方法模式(Template)模式
- C++之templateC++
- [Javascript] HTML Template InterpolationJavaScriptHTML
- [Javascript] template literal tagJavaScript
- elasticsearch之search templateElasticsearch
- Python:Template模板字串Python字串
- SpringBoot+ajax踩的坑Error resolving template, template might not exist or might not be accessibleSpring BootError
- c++11-17 模板核心知識(十四)—— 解析模板之依賴型模板名稱 Dependent Names of Templates(.template/->template/::template)C++
- 標準庫之template
- 一個簡單template engine
- C++開發:template,模板C++
- WPF 資料模板Data Template
- Vue中的template配置項Vue
- 0115 springboot template方式操作mongodbSpring BootMongoDB
- c++11-17 模板核心知識(十二)—— 模板的模板引數 Template Template ParametersC++
- 小程式 template 模版使用方法
- lecture8 Template Classes + Const Correctness
- Go HTML/template 模板使用方法GoHTML
- Angular 4.x template syntax & common directivesAngular
- 聊聊Vue.js的template編譯Vue.js編譯
- 定製化vue-cli Template/webpackVueWeb
- React騷操作——jsx遇到template-directiveReactJS
- 傳單模板:Flyer Design - Flyer Template for Indeisgn
- Kubernetes 中使用consul-template渲染配置
- id名跟 template之間使用注意
- go 模板(template)的常用基本語法Go
- vue3 template 特殊的標籤Vue