I am creating a grid at runtime. I am using the following code to apply a DataRowTemplate to each row for the grid:
Friend Class DataRowTemplate
Implements ITemplate
Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
Dim drt As New ASPxLabel
Dim sb As New StringBuilder()
sb.Append("<div style=""padding:5px;margin-bottom:25px;"">")
sb.Append("<table cellpadding=""2"" cellspacing=""1"" width=""650"" height=""100"">")
sb.Append("<tr>")
sb.Append("<td rowspan=""4""><img src=""img/rlogo.jpg""/></td>")
sb.Append("<td><b>LocationID</b></td>")
sb.Append("<td>Row 1</td>")
sb.Append("<td><b>ItemID</b></td>")
sb.Append("<td>123456</td>")
sb.Append("</tr>")
sb.Append("<tr>")
sb.Append("<td><b>Desc</b></td>")
sb.Append("<td colspan=""3"">Item description goes here.</td>")
sb.Append("</tr>")
sb.Append("<tr>")
sb.Append("<td><b>Breeder</b></td>")
sb.Append("<td >Breeder name goes here.</td>")
sb.Append("<td><b>Supplier</b></td>")
sb.Append("<td>Supplier name goes here.</td>")
sb.Append("</tr>")
sb.Append("<tr>")
sb.Append("<td colspan=""4"" style=""white-space:normal"">Insert Trial Data Here</td>")
sb.Append("</tr>")
sb.Append("</table>")
sb.Append("</div>")
drt.EncodeHtml = False
drt.Text = sb.ToString()
container.Controls.Add(drt)
End Sub
End Class
Using the code above, I want to populate the appropriate area with a value from each datarow. For instance, in the above code, it says "insert item description here". Item description is a column within the grid, but I can't figure out how to get that value for the row in the DataRowTemplate since it is created at runtime. Can you please provide a VB.NET example illustrating how this is done?
Thanks,
Jim
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.
Hello Jim,
The ASPxLabel is not capable for displaying tables. You should create a Table instance within the InstantiateIn method.
Thanks,
Nick
--------------------
Check if Search Engine is able to answer questions faster than I do!
Jim,
To obtain a data row object, typecast the container to GridViewDataRowTemplateContainer and use its DataItem property.
Thanks,
Nick
Nick,
Regarding your 1st reply: What is the reasoning for this? What I am currently doing works. Is there a situation where it wouldn't? Is there a limitation to this control? All I did was set the EncodeHTML property to false for the label control and it works fine.
Regarding your 2nd reply: This is the exact path that I was headed down before posting my question. I read that very help page that you posted a link to. The problem is, there is not an example for me to look at to see how this is done. I requested in my original post that an example be provided in VB.NET. I do not need an entire solution, just a code snippet on 1) how I would type cast the container as you suggested, then 2) how I would retrieve the specific column value from the DataItem object.
Thank you for your quick response.
Jim
Hello Jim,
Here are code samples, illustrating how to perform the required operations (see code below):
1). How to build the ASPxGridView.DataRowTemplate's content.
2). How to cast the "control" parameter of the InstantiateIn method to the GridViewDataRowTemplateContainer object.
3). How to retrieve a specific value of the DataItem object.
Public Class DataRowTemplate Implements ITemplate Public Sub InstantiateIn(ByVal container As Control) '//1// Dim table As New Table() table.CellPadding = 2 table.CellPadding = 1 table.Width = New Unit(650, UnitType.Pixel) table.Height = New Unit(100, UnitType.Pixel) Dim row As New TableRow() table.Rows.Add(row) Dim cell As New TableCell() '////// '//2// Dim tempateContainer As GridViewDataRowTemplateContainer = CType(container, GridViewDataRowTemplateContainer) '////// '//3// cell.Text = tempateContainer.Grid.GetRowValues(tempateContainer.VisibleIndex, REQUIRED_FIELD_NAME).ToString() '////// row.Cells.Add(cell) ... container.Controls.Add(table) End Sub End Class
Regards,
Mike
Mike,
Thank you for your last response. I tried your suggestions and it worked. However, I have another issue related to the use of DataRowTemplates that I need your assistance with.
Please refer to the attached document. I tried to be as detailed as possible. I included the code that populates my grid, as well as the class that I created for my data row template. I marked up the code with comments (seen in red) to help you understand what is happening and what I need. I also included a screenshot at the end that illustrates what the included code produces so you have a better picture when following the code.
Please let me know if you have any questions. This piece is critical to keeping my project on schedule, so the sooner you can reply the better. I appreciate all your help.
Thanks,
Jim
Hello Jim,
Thank you for a detailed description of the issue. I've reviewed your requirements and suggest that you implement the following scenario (see code below):
Dim dataSet As New DataSet() ... dataSet.Tables.Add(New DataTable() With {.TableName = "TABLE_NAME"})'ASPxGridView ... dataSet.Tables.Add(New DataTable()) 'Image dataSet.Tables.Add(New DataTable()) 'EmptyCell ... gv.Templates.DataRow = New DataRowTemplate(dataSet) ... Public Class DataRowTemplate Implements ITemplate Private dataSet As DataSet Public Sub New() End Sub '//1// Public Sub New(ByVal dataSet As DataSet) Me.dataSet = dataSet End Sub '////// '//2// Public Sub InstantiateIn(ByVal container As Control) '...Image -->> Me.dataSet.Tables("TABLE_NAME") ... End Sub '////// End Class
Regards,
Mike