This is a migrated thread and some comments may be shown as answers.

Change textbox dynamically on databinding

1 Answer 340 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
GlenB
Top achievements
Rank 1
GlenB asked on 15 Jun 2010, 08:16 AM
I'm sure this is an easy fix...but it has defeated me so far.

I am trying to set the text in a textbox dynamically at runtime according to what the current datarow items contain. I have been trying to create a simple test to get the syntax worked out but have been having no luck. I have been unable to locate the answer in the forums either.

My report consists of a main report which contains a sub-report. The sub-report is where the tbtest textbox is located. I am using SQL Datasources for both the main and sub reports.

The following code is located in the sub-report codebehind (VB):
    Private Sub detail_ItemDataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles detail.ItemDataBound 
        'Get the detail section object from sender 
        Dim section As Telerik.Reporting.Processing.DetailSection = DirectCast(sender, Telerik.Reporting.Processing.DetailSection) 
        'From the section object get the current DataRow 
        Dim row As System.Data.DataRow = DirectCast(section.DataObject.RawData, System.Data.DataRow) 
        If (row("Hospital") <> Nothing) AndAlso (row("Surgeon") <> Nothing) Then 
            Dim testTextbox As Telerik.Reporting.Processing.TextBox = DirectCast(section.ChildElements.Find("tbtest", True)(0), Telerik.Reporting.Processing.TextBox) 
            testTextbox.Value = "Hospital and Surgeon exist" 
        End If 
 
    End Sub 
 

When I try to run the report I get the following error:
An error has occured while processing DetailSection 'detail':
Unable to cast object of type 'DataObject' to type 'System.Data.DataRow'.


Any help would be appreciated. Thanks.

1 Answer, 1 is accepted

Sort by
0
GlenB
Top achievements
Rank 1
answered on 17 Jun 2010, 01:12 AM
I worked it out after watching this video: http://tv.telerik.com/watch/reporting/video/telerik-trainer-reporting-item-data-binding

User functions allow the ability to feed in data values, perform operations using them and then output a result to a textbox.

Hope this helps someone else out.
Tags
General Discussions
Asked by
GlenB
Top achievements
Rank 1
Answers by
GlenB
Top achievements
Rank 1
Share this question
or