Ticket Q374257
Visible to All Users

How to determine a data type of GridViewDataColumn at runtime if the ASPxGridView is bound with an empty data base

created 12 years ago

[DX Support team: this thread was cloned from ASPxGridView - How to determine a data type of GridViewDataColumn at runtime]

This only works if the grid has at least one data row.
If you, like us, send in a dataset with an empty model, the value will be null.
Is there anyway around this?

Answers approved by DevExpress Support

created 12 years ago (modified 12 years ago)

For future referens:

Visual Basic
Protected Overrides Function GetModelType() As Type Return GetType(MyDataModel) End Function Protected Sub PrepareEditForm(ByVal sender As Object, ByVal e As ASPxGridViewEditorEventArgs) Dim Type = GetModelType() Dim DataType = Type.GetProperty(e.Column.FieldName).PropertyType If DataType = GetType(Decimal) Then e.Editor.CssClass += "decimal " End If End Sub
    created 12 years ago (modified 12 years ago)

    Hello Bengt,
    If the ASPxGridView is bound with an empty data source, it knows nothing about value types of the source. I am afraid that in this case the only way to determine data types of columns is to check the data source directly. If the data source provides this information, you can find the same column in the ASPxGridView and set a corresponding default filter condition as demonstrated in the ASPxGridView - How to determine a data type of GridViewDataColumn at runtime ticket.

      Comments (3)
      BR BR
      Bengt Rutgersson 12 years ago

        Okey, I have already planned a Plan B where I check directly against the data source.
        Since the fieldname is corrensponding to the property in the data model it should be farily simple.

        DevExpress Support Team 12 years ago

          Bengt,
          Is the issue solved?

          BR BR
          Bengt Rutgersson 12 years ago

            I added a method in my user control that returns the current data model.
            Then I match the fieldname against the data model and check the datatype on the macthed properties
            in that model. Works like a charm!

            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.