Ticket T241471
Visible to All Users

Implementation to ITemplate not working...

created 10 years ago (modified 10 years ago)

Hi,

i have this code in my aspx:

ASPx
<dx:GridViewDataComboBoxColumn FieldName="SR_STATUS_NAME" Caption="Status" VisibleIndex="5" HeaderStyle-HorizontalAlign="Center" ReadOnly="true" EditFormSettings-Visible="False"> </dx:GridViewDataComboBoxColumn>

and it in server side

Visual Basic
Protected Sub gvProjectStatusTracker_DataBound(sender As Object, e As EventArgs) Handles gvProjectStatusTracker.DataBound Dim editItemtemplate = DirectCast(gvProjectStatusTracker.Columns("MASTER_SR_ID"), GridViewDataColumn).EditItemTemplate If Not IsNothing(editItemtemplate) Then For Each col As GridViewColumn In gvProjectStatusTracker.Columns Dim colData = DirectCast(col, GridViewDataColumn) If Not IsNothing(colData) AndAlso Not colData.EditFormSettings.Visible Then colData.EditItemTemplate = New TemplateEditItemReadonly() End If Next End If End Sub Public Class TemplateEditItemReadonly Implements ITemplate Public Sub New() End Sub Public Sub InstantiateIn(container As Control) Implements ITemplate.InstantiateIn Dim auxContainer As GridViewDataItemTemplateContainer = container Dim lblFieldName As New ASPxLabel lblFieldName.Text = DataBinder.Eval(container, auxContainer.Column.FieldName) auxContainer.Controls.Add(lblFieldName) container.Controls.Add(lblFieldName) End Sub End Class

but when i run and enter in edit mode my template not replace default… debug don't enter in

Visual Basic
InstantiateIn

método

my idea was use an existent template from another column represented by var above named "editItemtemplate" , but as it didn't work i implemented the recomendation… Is it possible, use a edititemtemplate from another column?

code:

ASPx
<EditItemTemplate> <%# Eval(Container.Column.FieldName)%> </EditItemTemplate>

Answers approved by DevExpress Support

created 10 years ago (modified 10 years ago)

Hello,

The purpose of this task is not clear to me. If you wish to assign the same EditItemTemplate to all data columns, I recommend you assign an instance of the TemplateEditItemReadonly class to the GridViewDataColumn.EditItemTemplate property. The InstantiateIn method will be automatically called when an ASPxGridView starts creating an edit form with column editors:

C#
Protected Sub grid_Init(ByVal sender As Object, ByVal e As EventArgs) Dim g As ASPxGridView = DirectCast(sender, ASPxGridView) Dim tempalte = New TemplateEditItemReadonly() For Each col As GridViewDataColumn In g.DataColumns col.EditItemTemplate = tempalte Next col End Sub

I have attached a sample project to illustrate this solution.
I see that you assign the TemplateEditItemReadonly object to the EditItemTemplate property, but in the InstantiateIn method, you use a container as the GridViewDataItemTemplateContainer-type object. I am not sure if I understand your scenario correctly. If the suggested solution does not meet your requirements, would you please describe it in greater detail?

    Comments (1)

      Thanks Vladimir, i was doing it on DataBound event not in Init as you have done…
      Thanks again!

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.