Ticket Q303346
Visible to All Users

GridViewDataItemTemplateContainer - DataItem's object type

created 14 years ago

Hi,
I'm trying to convert an existing project (using standard asp.net controls) to use Devexpress controls.
But I'm facing a problem with the ASPxGridView.
I have an object let's call it SearchResult and it looks something like this:
public class SearchResult
{
    public int ResultId {get;set;}
    public int ResultName {get;set;}
    public SomeItem[] SomeItems {get;set;}
}
I'm building my gridview in code-behind because I can't tell which columns needed before I get the searchresult.
To generate columns for the "SomeItems" property I'm generating Templates (GridViewDataColumn) using the ITemplate interface - like this:
private class TrackingFieldItemTemplate : ITemplate
{
     string _columnname;
     public TrackingFieldItemTemplate(string columnname)
     {
          _columnname = columnname;
     }
     #region ITemplate Members
     public void InstantiateIn(Control container)
     {
          Label l = new Label();
          l.DataBinding += new EventHandler(l_DataBinding);
          container.Controls.Add(l);
     }
     void l_DataBinding(object sender, EventArgs e)
     {
          Label label = (Label)sender;
          label.Text = "Unknown";
          GridViewDataItemTemplateContainer container = (GridViewDataItemTemplateContainer)label.NamingContainer;
          TrackingFieldDisplay tfd = ((DocumentDisplay)container.DataItem).SomeItems.Find(msg => msg.TrackingFieldTypeName.Equals(_columnname));
          if (tfd != null)
               label.Text = tfd.TrackingFieldValue;
     }
     #endregion
}
My problem is that container.DataItem is not my databound object - and therefore the above code will of course throw an exception.
But how can I retrieve the databound object in my ITemplate implementation?
Thanks!
/Mikkel

Comments (3)

    Hello Mikkel,
    We've put your inquiry on our support queue. For the time being, we need to clarify your license status.
    I see that your products list doesn't contain registered versions of our controls. According to our EULA, you can evaluate our products for only a month, regardless of the number of times you re-installed our controls. The trial period starts after you start using our products and lasts for 30 days. Unless I am mistaken, you have been using our controls for longer than that. You possibly used another account to install the registered (not trial) version of our products. If so, please specify its registered email address. It is safe, since we've marked this issue as Private.
    Regards,
    Mike

    ?
    Unknown 14 years ago

      For some reason I always find the solution right after I've posted a question here :)
      Anyway, the solution I found was:
      GridViewDataItemTemplateContainer container = (GridViewDataItemTemplateContainer)label.NamingContainer;
      ASPxGridView gridView = container.Grid;
      SomeItem someItem = (SomeItem)gridView.GetRow(container.VisibleIndex);
      /Mikkel

        Mikkel,
        We are glad to hear that you have found a solution :)
        Thanks,
        Mike

        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.