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

Modify Textbox Data in Event

8 Answers 525 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Brad Perniciaro
Top achievements
Rank 1
Brad Perniciaro asked on 17 Jan 2008, 03:29 PM
I've been searching around for a way to change the 'Value' of a textbox during the ItemDataBound event, but I'm not seeing any examples.  I am binding to a SQLDataAdapter which calls a stored procedure to load the textboxes, so much of the data is stored in 'bit' column types.  What I need to do is simply change things like bit values '1' or '0' to 'Enabled' and 'Disabled' when the report is generated.

My first approach was to access the needed Textboxes in the ItemDataBound event and change their 'Text' or 'Value' field based on the appropriate row value.  But, these properties don't exist. 

Thanks.

8 Answers, 1 is accepted

Sort by
0
Brad Perniciaro
Top achievements
Rank 1
answered on 17 Jan 2008, 07:12 PM
Ok I'm slightly closer to my goal but still having a problem.  Let me back up and explain what I originally tried.  Based on the example in help, I took an approach similar to this:

Private Sub detail_ItemDataBound(ByVal sender As Object, ByVal e As System.EventArgs)  
    Dim section As Processing.DetailSection = TryCast(sender, Processing.DetailSection)  
    Dim extraShipping As Processing.ReportItemBase = section.Items.Find("extraShippingCostTextBox", False)(0)  
    Dim row As DataRowView = TryCast(section.DataItem, DataRowView)  
    If Nothing <> row Then  
        Dim val As Object = row.Row("Weight")  
        If Not (TypeOf val Is DBNull) AndAlso (DirectCast(val, Decimal)) > 10 Then  
            extraShipping.Visible = True 
        Else  
            extraShipping.Visible = False 
        End If  
    End If  
End Sub 

First off, I kept getting an error on 'If Nothing <> row Then' and had to change it to 'If NOT row is NOTHING Then' in order to get it to compile. 

Second, I tried to get a reference to my textbox using code similar to:

 Dim extraShipping As Processing.ReportItemBase = section.Items.Find("extraShippingCostTextBox", False)(0)  
 

However, it was here that I got stuck previously because I could not reference the 'Value' property my textbox analogous to the 'extraShipping' here.  To get around this problem, I found that I could just reference the name of the textbox directly in my code using the name of the element (myTextBox.Value).  This seems to work except for one small detail, the change that I'm applying in my ItemDataBound event never gets applied to the first item in the collection.  Here is my code:

Private Sub DetailSection1_ItemDataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailSection1.ItemDataBound  
    Dim section As Processing.DetailSection = DirectCast(sender, Processing.DetailSection)  
 
    Dim row As DataRowView = TryCast(section.DataItem, DataRowView)  
    Dim value As Object  
    If Not row Is Nothing Then  
      'Cassette A Out of Service  
      value = row.Row("CassAOutOfService")  
      If CType(value, String) = "False" Then  
        tbCassAState.Value = "Out of Service" 
      End If  
    End If  
  End Sub 

It seems that when I change the 'Value' property of the TextBox, it gets applied to the next item in the report, not the DataItem that I'm binding to.  So, if I change the Value to 'Out of Service' when I'm processing the 3rd Item in the report, the change is actually made to the 4th Item in the report. 

I have even tried to port all of my code into the ItemDataBinding event instead, but am experiencing the same phenomena.


Any advice or direction would be appreciated, thanks.
0
Brad Perniciaro
Top achievements
Rank 1
answered on 17 Jan 2008, 07:49 PM
I believe I have resolved the problem.  Instead of casting the textbox as a 'ReportItemBase' object like in the example, I cast it as a textbox instead and the 'Text' property becomes visible. I assume that the reason you have to get a reference of the textbox using the Section.Items.Find() is precisely because the reference to the current textbox is already pointing at the next item?
0
Ivan
Telerik team
answered on 18 Jan 2008, 05:40 PM
Hello Brad,

Thank you for contacting Telerik Support.

About your first question you can use an expression in the Value property:
myTextBoxItem.Value = "=IIF(Fields.myData=1,'Enabled','Disabled')";

If the data field is nullable, then simlpy elaborate some more:
myTextBoxItem.Value = "=IIF(Fields.myData=1,'Enabled',IIF(Fields.myData=0,'Disabled',''))";

About the case with ItemDataBound event handler: if you need to change the value of a text box item you should cast to Telerik.Reporting.Processing.TextBox in order to access the Text property. For example:

private void myTextBox_ItemDataBound(object sender, System.EventArgs e) 
    Telerik.Reporting.Processing.TextBox textBox = 
        sender as Telerik.Reporting.Processing.TextBox; 
    textBox.Text = "some new value"
 
private void detail_ItemDataBound(object sender, System.EventArgs e) 
    Telerik.Reporting.Processing.DetailSection section = 
        sender as Telerik.Reporting.Processing.DetailSection; 
    Telerik.Reporting.Processing.TextBox textBox = 
        section.Items["MyTextBox"as Telerik.Reporting.Processing.TextBox; 
    textBox.Text = "some new value"

More information on the available properties you can find in the API Reference topic in the Reporting documentation. For example Telerik.Reporting.Processing.ReportItemBase has an Items property, but Telerik.Reporting.Processing.TextBox has a Text one.

Please note that Telerik Reporting supports user defined functions as well, which can help in almost any case.

I hope this information helps.
 

Regards,
Ivan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Lalit
Top achievements
Rank 1
answered on 27 Apr 2013, 07:23 AM
Hi,
I am using the detail section databound evnet to access all the text boxes contained in it and after getting all the child elements of detailsection(textboxes), I am setting the visibility of some text boxes false.But it does not make any effect on rendered report.
Please help me
Thanks in advance

Here is my code snippet

private void detail_ItemDataBound(object sender, EventArgs e)
        {
            Telerik.Reporting.Processing.DetailSection procDetail = sender as Telerik.Reporting.Processing.DetailSection;
            for (int i = 0; i < count; i++)
            {
                Telerik.Reporting.Processing.TextBox nameTxt = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox1", true)[i];

                Telerik.Reporting.Processing.TextBox txtApprovedDate = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "txtApprovedDate", true)[i];
                Telerik.Reporting.Processing.TextBox txtApprovedBy = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "txtApprovedBy", true)[i];

                Telerik.Reporting.Processing.TextBox txtSuggestedDate = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "txtSuggestedDate", true)[i];
                Telerik.Reporting.Processing.TextBox txtSuggestedBy = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "txtSuggestedBy", true)[i];

                Telerik.Reporting.Processing.TextBox username = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "username", true)[i];
                Telerik.Reporting.Processing.TextBox Email = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "Email", true)[i];

                Telerik.Reporting.Processing.TextBox Enabled = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "Enabled", true)[i];
                Telerik.Reporting.Processing.TextBox Locked = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "Locked", true)[i];

                Telerik.Reporting.Processing.TextBox textBox38 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox38", true)[i];
                Telerik.Reporting.Processing.TextBox textBox40 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox40", true)[i];

                Telerik.Reporting.Processing.TextBox textBox20 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox20", true)[i];



                Telerik.Reporting.Processing.TextBox textBox42 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox42", true)[i];
                Telerik.Reporting.Processing.TextBox textBox44 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox44", true)[i];

                Telerik.Reporting.Processing.TextBox textBox9 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox9", true)[i];
                Telerik.Reporting.Processing.TextBox textBox11 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox11", true)[i];

                Telerik.Reporting.Processing.TextBox textBox13 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox13", true)[i];
                Telerik.Reporting.Processing.TextBox textBox18 = (Telerik.Reporting.Processing.TextBox)Telerik.Reporting.Processing.ElementTreeHelper.FindChildByName(procDetail, "textBox18", true)[i];

                if (string.IsNullOrEmpty(nameTxt.Text))
                {

                    txtApprovedDate.Visible = false;
                    txtApprovedBy.Visible = false;

                    txtSuggestedDate.Visible = false;
                    txtSuggestedBy.Visible = false;

                    username.Visible = false;
                    Email.Visible = false;

                    Enabled.Visible = false;
                    Locked.Visible = false;

                    textBox38.Visible = false;
                    textBox40.Visible = false;

                    textBox20.Visible = false;


                }
                else
                {
                    textBox42.Visible = false;
                    textBox44.Visible = false;


                    textBox9.Visible = false;
                    textBox11.Visible = false;


                    textBox13.Visible = false;
                    textBox18.Visible = false;


                }
            }
        }
0
Lalit
Top achievements
Rank 1
answered on 27 Apr 2013, 07:27 AM
I have also used this..

private void detail_ItemDataBound(object sender, EventArgs e)
        {
            //Telerik.Reporting.TableGroup group1 = new Telerik.Reporting.TableGroup();
            //group1.Name = "UserProfile";
            //group1.Groupings.Add(new Telerik.Reporting.Grouping("=Fields.UserProfile"));
            
            Telerik.Reporting.Processing.DetailSection procDetail = sender as Telerik.Reporting.Processing.DetailSection;
            for (int i = 0; i < count; i++)
            {
                Telerik.Reporting.Processing.TextBox nameTxt = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox1", true)[i];
                
                Telerik.Reporting.Processing.TextBox txtApprovedDate = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtApprovedDate", true)[i];
                Telerik.Reporting.Processing.TextBox txtApprovedOn = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtApprovedOn", true)[i];
                Telerik.Reporting.Processing.TextBox txtApprovedBy = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtApprovedBy", true)[i];
                Telerik.Reporting.Processing.TextBox txtApprovedBy1 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtApprovedBy1", true)[i];
                
                Telerik.Reporting.Processing.TextBox txtSuggestedDate = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtSuggestedDate", true)[i];
                Telerik.Reporting.Processing.TextBox txtSuggestedOn = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtSuggestedOn", true)[i];
                Telerik.Reporting.Processing.TextBox txtSuggestedBy = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtSuggestedBy", true)[i];
                Telerik.Reporting.Processing.TextBox txtSuggestedBy1 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtSuggestedBy1", true)[i];

                Telerik.Reporting.Processing.TextBox username = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("username", true)[i];
                Telerik.Reporting.Processing.TextBox txtUserName = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtUserName", true)[i];
                Telerik.Reporting.Processing.TextBox Email = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("Email", true)[i];
                Telerik.Reporting.Processing.TextBox txtEmail = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtEmail", true)[i];

                Telerik.Reporting.Processing.TextBox Enabled = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("Enabled", true)[i];
                Telerik.Reporting.Processing.TextBox txtEnabled = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtEnabled", true)[i];
                Telerik.Reporting.Processing.TextBox Locked = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("Locked", true)[i];
                Telerik.Reporting.Processing.TextBox txtLocked = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("txtLocked", true)[i];

                Telerik.Reporting.Processing.TextBox textBox38 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox38", true)[i];
                Telerik.Reporting.Processing.TextBox textBox39 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox39", true)[i];
                Telerik.Reporting.Processing.TextBox textBox40 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox40", true)[i];
                Telerik.Reporting.Processing.TextBox textBox41 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox41", true)[i];

                Telerik.Reporting.Processing.TextBox textBox20 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox20", true)[i];
                Telerik.Reporting.Processing.TextBox textBox6 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox6", true)[i];

                //group
                //group1.ReportItem = txtApprovedDate;

                Telerik.Reporting.Processing.TextBox textBox42 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox42", true)[i];
                Telerik.Reporting.Processing.TextBox textBox43 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox43", true)[i];
                Telerik.Reporting.Processing.TextBox textBox44 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox44", true)[i];
                Telerik.Reporting.Processing.TextBox textBox45 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox45", true)[i];

                Telerik.Reporting.Processing.TextBox textBox9 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox9", true)[i];
                Telerik.Reporting.Processing.TextBox textBox47 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox47", true)[i];
                Telerik.Reporting.Processing.TextBox textBox11 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox11", true)[i];
                Telerik.Reporting.Processing.TextBox textBox49 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox49", true)[i];

                Telerik.Reporting.Processing.TextBox textBox13 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox13", true)[i];
                Telerik.Reporting.Processing.TextBox textBox51 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox51", true)[i];
                Telerik.Reporting.Processing.TextBox textBox18 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox18", true)[i];
                Telerik.Reporting.Processing.TextBox textBox53 = (Telerik.Reporting.Processing.TextBox)procDetail.ChildElements.Find("textBox53", true)[i];
                if (string.IsNullOrEmpty(nameTxt.Text))
                {
                    //procTxtColor.Visible = false;
                    //procTxtColor.Height.Equals(0);
                    //procLblColor.Visible = false;
                    //procLblColor.Height.Equals(0);
                    //procLblColor1.Visible = false;
                    //procLblColor1.Height.Equals(0);
                    //procTxtColor1.Visible = false;
                    //procTxtColor1.Height.Equals(0);
                    txtApprovedDate.Visible = false;
                    txtApprovedOn.Visible = false;
                    txtApprovedBy.Visible = false;
                    txtApprovedBy1.Visible = false;

                    txtSuggestedDate.Visible = false;
                    txtSuggestedOn.Visible = false;
                    txtSuggestedBy.Visible = false;
                    txtSuggestedBy1.Visible = false;

                    username.Visible = false;
                    txtUserName.Visible = false;
                    Email.Visible = false;
                    txtEmail.Visible = false;

                    Enabled.Visible = false;
                    txtEnabled.Visible = false;
                    Locked.Visible = false;
                    txtLocked.Visible = false;

                    textBox38.Visible = false;
                    textBox39.Visible = false;
                    textBox40.Visible = false;
                    textBox41.Visible = false;

                    textBox20.Visible = false;
                    textBox6.Visible = false;
                    

                }
                else
                {
                    textBox42.Visible = false;
                    textBox43.Visible = false;
                    textBox44.Visible = false;
                    textBox45.Visible = false;

                    textBox9.Visible = false;
                    textBox47.Visible = false;
                    textBox11.Visible = false;
                    textBox49.Visible = false;

                    textBox13.Visible = false;
                    textBox51.Visible = false;
                    textBox18.Visible = false;
                    textBox53.Visible = false;
                    
                }
            }
        }
0
Squall
Top achievements
Rank 1
answered on 29 Apr 2013, 10:50 AM
You have to use Bindings instead of events.

SN
0
Napa
Top achievements
Rank 1
answered on 04 Jun 2013, 03:19 PM
is your problem solved?could you post working code and i have same problem.
0
Stef
Telerik team
answered on 07 Jun 2013, 02:22 PM
Hi Napa,

Please check the answer posted here.

In future please avoid double posting or posting question not related to the main topic discussed in the thread. Thus there is more likely other community members to notice your post and help you.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

Tags
General Discussions
Asked by
Brad Perniciaro
Top achievements
Rank 1
Answers by
Brad Perniciaro
Top achievements
Rank 1
Ivan
Telerik team
Lalit
Top achievements
Rank 1
Squall
Top achievements
Rank 1
Napa
Top achievements
Rank 1
Stef
Telerik team
Share this question
or