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

User Control Grid Edit Form Issue

2 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris Jeunelot
Top achievements
Rank 1
Chris Jeunelot asked on 10 May 2010, 10:41 PM
How do i use ajax to show a textbox on a grid's user control's edit form?
As an example I am using the sample http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx
as a user control on my page. The edit of the page uses the EmployeeDetailsCS.ascx with 2 controls added: 1 checkbox (chkReferral) and 1 textbox (txtReferralOther). When i check the chkReferral i want to show the txtReferral.  Somewhere down the line my onclick event for my checkbox is not getting processed and not able to trigger the visibility of the textbox on the client side. I am getting an Object not found error. Anyone have any example code of how this can be accomplished?
Thanks
Chris

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 11 May 2010, 06:44 AM
Hello Chris,

You can set the visibility of the textbox based on checkbox  status by using following code. I hope it helps you.

C#:

 protected
 void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode) 
        { 
            GridEditFormItem insertitem = (GridEditFormItem)e.Item; 
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); 
            CheckBox ch = (CheckBox)userControl.FindControl("CheckBox1"); 
            TextBox txt = (TextBox)userControl.FindControl("TextBox1"); 
            ch.Attributes.Add("onclick""OnClick(this, '"+txt.ClientID+"');");             
        } 
    } 

Java Script:

 <script type=
"text/jscript"
    function OnClick(checkbox, textboxClientID) 
      { 
        var textBox = document.getElementById(textboxClientID); 
        if (checkbox.checked)  
          { 
            textBox.style.display = "none"
          } 
        else 
          { 
            textBox.style.display = "block"
          } 
      } 
</script> 

Regards,
Shinu.







0
Chris Jeunelot
Top achievements
Rank 1
answered on 12 May 2010, 03:20 PM
Thanks
Thats exactly what I needed.
Tags
Grid
Asked by
Chris Jeunelot
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Chris Jeunelot
Top achievements
Rank 1
Share this question
or