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

Rad grid want to add text boxes on add new button

3 Answers 163 Views
Grid
This is a migrated thread and some comments may be shown as answers.
girish
Top achievements
Rank 1
girish asked on 29 Oct 2010, 05:19 AM
Hi,
I want to add text boxes on add new button.

for ex. if i click on add new button i want to generate text boxes on each and every row

and also want to catch its value of each and every text box that i want to generate after clicking on add new button.

Please help me on this.

Thank you.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Oct 2010, 07:30 AM
Hello Girish,

You can achieve this by creating a GridTemplateColumn with TextBox inside ItemTemplate in aspx and initially setting its visibility as 'False'. Then in PreRender event when the grid is in insert mode set the TemplateColumn's visibility as 'True' to show the TextBox for each row.

ASPX:
<telerik:GridTemplateColumn UniqueName="GridTemplateColumn" Visible="false">
    <ItemTemplate>
        <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
    </ItemTemplate>
</telerik:GridTemplateColumn>

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
   {
       if (RadGrid1.MasterTableView.IsItemInserted)
       {
           (RadGrid1.MasterTableView.GetColumn("GridTemplateColumn") as GridTemplateColumn).Visible = true;
       }
       else
          (RadGrid1.MasterTableView.GetColumn("GridTemplateColumn") as GridTemplateColumn).Visible = false;
   }


You can access the value of each TextBox in grid row by looping through each grid item .

C#:
   foreach (GridDataItem item in RadGrid1.Items)//loops through each item
        {
           TextBox txt = (TextBox)item.FindControl("TextBox1"); //accessing control
           string value = txt.Text; //get the value
        }
      

Thanks,
Princy.
0
girish
Top achievements
Rank 1
answered on 29 Oct 2010, 08:38 AM
hi,
thank for reply it work but what exactly i want i want to add test box in each and every row when i click on add new button in this scenario what happens is text box created ONLY ONCE. I WANT 2 CREATE ON EACH AND EVERY ADD NEW BUTTON IN EACH ROW WITH PREVIOUS TEXT BOX AND WANT TO GET ALL VALUES ALSO.
0
Marin
Telerik team
answered on 29 Oct 2010, 01:18 PM
Hello girish,

The RadGrid does not support such functionality by default. However there are various workarounds and one of them is discussed in this forum thread also there is a live demo showing similar functionality with insertion of multiple items at once.

Sincerely yours,
Marin
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
girish
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
girish
Top achievements
Rank 1
Marin
Telerik team
Share this question
or