How to change the content of a textbox programmatically

5 posts, 0 answers
  1. Stephan
    Stephan avatar
    71 posts
    Member since:
    Jul 2007

    Posted 16 Jan 2009 Link to this post

    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
  2. Jafin
    Jafin avatar
    86 posts
    Member since:
    Nov 2005

    Posted 18 Jan 2009 Link to this post

    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(); 
       } 


  3. DevCraft banner
  4. Stephan
    Stephan avatar
    71 posts
    Member since:
    Jul 2007

    Posted 19 Jan 2009 Link to this post

    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.


  5. Steve
    Admin
    Steve avatar
    10941 posts

    Posted 19 Jan 2009 Link to this post

    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.
  6. Stephan
    Stephan avatar
    71 posts
    Member since:
    Jul 2007

    Posted 19 Jan 2009 Link to this post

    He Steve,

    great, that is even better in our situation.

    thx
Back to Top
DevCraft banner