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

[Solved] Dynamically Generate Textbox

2 Answers 504 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ajit
Top achievements
Rank 1
Ajit asked on 25 May 2009, 06:15 AM
Hi,

 i want to generate dynamic textbox inside radgrid insert or edit template wheneever add button is clicked and textbox getremoved when remove button is clicked

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 May 2009, 06:50 AM
Hello Ajit,

You can try out the following code on the click of the buttons as shown in the code below:
aspx:
 <EditFormSettings EditFormType="Template" > 
        <FormTemplate> 
             <asp:Button ID="btnAdd"  runat="server" Text="Add" OnClick="btnAdd_Click" /> 
              
             <asp:Button ID="btnRemove"  runat="server" Text="Remove" OnClick="btnRemove_Click" />  
        </FormTemplate>          
 </EditFormSettings> 

c#:
  protected void btnAdd_Click(object sender, EventArgs e) 
    { 
 
        Button btnAdd = (Button)sender; 
        GridEditFormItem editfromItem = (GridEditFormItem)btnAdd.NamingContainer; 
        TextBox txt = new TextBox(); 
        txt.ID = "TextAdd"
        txt.Width = Unit.Pixel(100); 
        editfromItem.Cells[1].Controls.Add(txt); 
    } 
    protected void btnRemove_Click(object sender, EventArgs e) 
    { 
        Button btnRemove = (Button)sender; 
        GridEditFormItem editfromItem = (GridEditFormItem)btnRemove.NamingContainer; 
        TextBox txtRem = (TextBox)editfromItem.FindControl("TextAdd"); 
        if (txtRem != null) 
        { 
            editfromItem.Cells[1].Controls.Remove(txtRem); 
        } 
    } 

Thanks
Princy.
0
Ajit
Top achievements
Rank 1
answered on 25 May 2009, 01:07 PM
Thank's
           Princy...

can you provide me some code on client side..................i.e using Javascript
Tags
Grid
Asked by
Ajit
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Ajit
Top achievements
Rank 1
Share this question
or