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
- html templateHTML
- Raise Server-Side Click Event of CheckBox in a DataGrid Template ColumnAIServerIDE
- ES 筆記十四:Index Template 和 Dynamic Template筆記Index
- c++ 模板模板引數("Template Template Parameters")C++
- go template使用Go
- BaiDu TemplateAI
- Django模板templateDjango
- Js template engineJS
- artTemplate js templateJS
- C_template
- Mendix Page Template
- ansible template
- 模板方法模式(Template)模式
- Vue template To JSXVueJS
- elasticsearch之search templateElasticsearch
- Oracle ASM Template DirectoryOracleASM
- Abstract Factory + Template = BuilderUI
- 關於Template模式模式
- ASM Disk Group TemplateASM
- [Javascript] template literal tagJavaScript
- C++之templateC++
- Python:Template模板字串Python字串
- ansible之template模組
- ASP.NET MVC TemplateASP.NETMVC
- Python Template 錯誤Python
- oracle controlfile template;Oracle
- 標準庫之template
- c++11-17 模板核心知識(十四)—— 解析模板之依賴型模板名稱 Dependent Names of Templates(.template/->template/::template)C++
- You are using the runtime-only build of Vue where the template compiler is not available.UIVueCompileAI
- template might not exist or might not be accessible by any of the configured Template Resolvers
- C++開發:template,模板C++
- 設計模式-Template Method Pattern設計模式
- asm中template特性測試!ASM
- Vue中的template配置項Vue
- [Javascript] HTML Template InterpolationJavaScriptHTML
- WPF 資料模板Data Template
- c++11-17 模板核心知識(十二)—— 模板的模板引數 Template Template ParametersC++