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

Report table datasource challenge

3 Answers 106 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 19 Aug 2011, 03:03 PM
I have created a RadGridView in my application to use as an employee attendance calendar. The datasource is a SQL Server table with 1 column for the name of the month and 31 columns for the days of the month. In the database only the MonthName column has data in it; one record for each month. The columns for the days of the month are empty in the database. Basically this is just a template.

The day-of-the-month columns in the RadGridView are populated using a SQLDataReader. Like this;

Private Sub FillCalendar()
       Dim newFont = New Font("Calibri", 7.0F, FontStyle.Bold)
       Dim EE As Integer
       Dim vbYear As Integer
       Dim Incident As String
       Dim ColIndex As Integer 'Day of the month, also the name of the column
       Dim RowIndex As Integer ' Month of the year, also row index + 1 
       EE = CInt(RadTextBoxElement10.Text) ' Employee id #
       vbYear = CInt(RadDropDownListElement1.SelectedIndex + 2007) 'Year for calendar
       'connection string and mysqlconnect
       Dim connstring As String = ("Data Source=MyServer\SQLINSTANCE;Initial Catalog=DATABASENAME;Persist Security Info=True;User ID=MYUSER;Password=MYPASS")
       Dim conn As New SqlConnection(connstring)
       Dim selectSQL As String
       'create selection query
       selectSQL = ("Select aDay, aMonth, Incidents From View_AttCombined Where (GPID like '" & EE & "') and (aYear like '" & vbYear & "')")
       'create selection command
       Dim cmd As New SqlCommand(selectSQL, conn)
       'set cmd property
       cmd.CommandType = CommandType.Text
       'open database
       conn.Open()
       'create and execute the reader
       Dim myreader As SqlDataReader = cmd.ExecuteReader
       While myreader.Read
           ColIndex = myreader.GetInt32(0)
           RowIndex = myreader.GetInt32(1) - 1
           Incident = myreader.GetString(2)
           Me.RadGridView1.Rows(RowIndex).IsCurrent = True
           Me.RadGridView1.Columns(ColIndex).IsCurrent = True
           Me.RadGridView1.CurrentCell.Value = Incident
           If Len(Me.RadGridView1.CurrentCell.Value) > 3 Then
               Me.RadGridView1.CurrentCell.Font = newFont
           Else
           End If
       End While
       conn.Close()
       Me.AttendanceTableAdapter.Fill(Me.AttendanceDataSet.Attendance, CInt(RadTextBoxElement10.Text), CInt(RadDropDownListElement1.SelectedIndex + 2007))
       Me.AttCalCommentsTableAdapter.Fill(Me.CalCommentDataSet.AttCalComments, CInt(RadTextBoxElement10.Text), CInt(RadDropDownListElement1.SelectedIndex + 2007))
       Me.RadGridView1.CurrentRow = Me.RadGridView1.Rows(0)
       Me.RadGridView1.CurrentColumn = Me.RadGridView1.Columns(1)
   End Sub

Is it possible to use a similar approach to populate the Cells/TextBox's in a report table?
If not, is it possible to use a RadGridView as the datasource for a report table?

I am open to other suggestions.

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 22 Aug 2011, 04:38 PM
Hi James,

Telerik Reporting crosstab item is capable of displaying data in calendar format. However the approach is quite different from the RadGrid because Telerik Reporting as a reporting solution depends on declarative report definition that is processed based on the provided data. Check out the Creating a Calendar Report with Telerik Reporting that elaborates on the topic topic.

Additionally you may find useful the following help articles:
Best wishes,
Peter
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
James
Top achievements
Rank 1
answered on 22 Aug 2011, 05:12 PM
Thanks for the reply. I will give the Crosstab item a look and see if I can make it work.
While I am looking at the crosstab item, let me trouble with two more questions.

Is it possible to do either of the following;

1.) Convert a RadGridView to a datasource that can be used in a report?

2.) Is it possible to do something like the following?
    

 

Private Sub TextBox11_ItemDataBinding(sender As System.Object, e As System.EventArgs) Handles TextBox11.ItemDataBinding 
TextBox11.Value = Main.RadGridView1.Rows(1).Cells(1).Value
End Sub

where TextBox11 is a TextBox within a report table 

Thanks,

0
Peter
Telerik team
answered on 23 Aug 2011, 02:59 PM
Hi James,

Generally Telerik Reporting data items can utilize as datasource Telerik Reporting DataSource components. The datasource components support a range of databases, ORMs and any type that implements IEnumerableIListSourceIDbDataAdapter or System.Type that represent business objects. However the RadGridView is not a data type that can be directly used as datasource.

You can set the TextBox.Value in TextBox.ItemDataBinding but the report items ItemDataBinding is fired just before the item is bound to data. Thus if the Textbox parent data item doesn't have datasource set, the textbox.ItemDataBinding will be fired only once.

All the best,
Peter
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
General Discussions
Asked by
James
Top achievements
Rank 1
Answers by
Peter
Telerik team
James
Top achievements
Rank 1
Share this question
or