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

How to change the content of a textbox programmatically

7 Answers 241 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stephan
Top achievements
Rank 1
Stephan asked on 16 Jan 2009, 12:35 PM
Hi, Im sure it is possible, but I don t know how to do it. In designtime a added textboxes containing a label. In my webapplication I want to change the content of this label. When I debug I can see the textbox and its value. But how to reference the textbox in order to change its value.

Any help is appreciated.

Thx

7 Answers, 1 is accepted

Sort by
0
Jafin
Top achievements
Rank 2
answered on 19 Jan 2009, 02:30 AM
In the Telerik help theres an example subscribing to the ItemDataBound event.  This would allow you to, Find/reference your textbox control and then replace its contents with something else:

using System.Data; 
using Processing = Telerik.Reporting.Processing; 
 
//... 
private void detail_ItemDataBound(object sender, System.EventArgs e) 
{             
   // Get the detail section object from sender 
   Processing.DetailSection section = (Processing.DetailSection)sender; 
   // From the section object get the DataRowView 
   DataRowView dataRowView = (DataRowView)section.DataItem; 
   // Also from the section object get the items in the report 
   Processing.ReportItemBase[] items = 
           (Processing.ReportItemBase[])section.Items.Find("tbCombined"false); 
   /// Get the specific report item you want to change, 
   /// use the dataRowView to get the underlying data, 
   /// then change the report item properties based on the data. 
   if (items.Length > 0) 
   { 
       Processing.TextBox item = items[0] as Processing.TextBox; 
       item.Value = 
           dataRowView["FirstName"].ToString() 
           + " " + 
           dataRowView["LastName"].ToString(); 
   } 


0
Stephan
Top achievements
Rank 1
answered on 19 Jan 2009, 11:12 AM
Hi Jafin,

that was what I was looking for. At first I thought is was possible on the page where the report is shown (rendered), but I see I have to do it in the report itselft.

Thanks for the help.


0
Steve
Telerik team
answered on 19 Jan 2009, 05:02 PM
Hello Stephan,

This is possible through the calling application as well. Here is a sample:

   protected void Button1_Click(object sender, EventArgs e) 
        { 
            Telerik.Reporting.TextBox txt = this.ReportViewer1.Report.Items.Find("textBox1"true)[0] as Telerik.Reporting.TextBox; 
            txt.Value = "set through app"
        } 

Hope this helps.

Sincerely yours,
Steve
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Stephan
Top achievements
Rank 1
answered on 19 Jan 2009, 09:45 PM
He Steve,

great, that is even better in our situation.

thx
0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 26 Jan 2021, 04:18 PM

Hello

it looks like the last proposed solution

    Dim txt As Telerik.Reporting.TextBox = TryCast(Me.ReportViewer1.Report.Items.Find("textBox1", True)(0), Telerik.Reporting.TextBox)
    txt.Value = "set through app"

is now obsolete and I could not find the replacement syntax ...

Thanks for providing the new syntax

Regards

Pierre-Jean

0
Neli
Telerik team
answered on 29 Jan 2021, 06:55 AM

Hello Pierre-Jean,

You can take a look at Access Report Items Programmatically which provides different approaches in C#/VB for accessing a report item from within the report and from the invoking application. 

Let us know if you need further help.

Regards,
Neli
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
pierre-jean
Top achievements
Rank 1
Veteran
Iron
answered on 06 Feb 2021, 03:15 PM

Thanks a lot

I'll give it a try and Keep you posted

Best regards

Pierre-Jean

Tags
General Discussions
Asked by
Stephan
Top achievements
Rank 1
Answers by
Jafin
Top achievements
Rank 2
Stephan
Top achievements
Rank 1
Steve
Telerik team
pierre-jean
Top achievements
Rank 1
Veteran
Iron
Neli
Telerik team
Share this question
or