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

Pre Populate a RadGrid's FormTemplate

3 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 19 Apr 2011, 08:51 PM
I have a grid and I'm using the grid's FormTemplate to edit and insert records into the SQL database.
<EditFormSettings EditFormType="Template">
     <FormTemplate>
          .....
     </FormTemplate>
</EditFormSettings>

In this project that I'm working on I want to be able to select a record, take that data and populate the form WITHOUT adding the record first. Here is the button in the grid:
<telerik:GridButtonColumn 
     ButtonType="ImageButton" 
     CommandName="CopyPaste" 
     ConfirmDialogType="RadWindow" 
     ConfirmText="Copy information?" 
     ConfirmTitle="Copy" 
     ImageUrl="/Images/SmallRecycle.png"
     Text="Copy" 
     UniqueName="CopyColumn"/>

I can easily duplicate the record in the database, but the idea is that someone enters information and the next bit of information is the same with the exception of the person tied to the record. I don't want them to have to retype the information and I don't want to write a new record and have them edit it.

Does this make sense? I'm really stuck on expanding the grid's form and filling the fields.

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Apr 2011, 02:24 PM
Hello Michael,

You can access the each cell value in selected row and populate corresponding control in insert form with that data. Sample code is given below.

ASPX:
<EditFormSettings EditFormType="Template">
     <FormTemplate>
           <asp:TextBox ID="TextBox2" runat="server" Text='<%#Bind("FirstName") %>'>
       </asp:TextBox>
     </FormTemplate>
</EditFormSettings>

C#:
protected void RadGrid1_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
   {
       if (e.CommandName == "CopyPaste")
       {
           GridDataItem item = (GridDataItem)e.Item;
           GridEditFormInsertItem insertItem = (GridEditFormInsertItem)RadGrid1.MasterTableView.GetInsertItem();//getting insert row
           TextBox txtname = (TextBox)insertItem.FindControl("TextBox2");//acces control in insert form
           txtname.Text = item["FirstName"].Text;//populate TextBox with corresponding cell value
       }
   }

Thanks,
Princy.
0
Michael
Top achievements
Rank 1
answered on 20 Apr 2011, 02:37 PM
Thanks Princy, but what I'm looking for is being able to trigger the same event used for "Add new record" and then populate the fields with selected data.
0
Princy
Top achievements
Rank 2
answered on 21 Apr 2011, 06:48 AM
Hello,

You can do this by setting the IsItemInserted property of RadGrid As true. Try the following snippet code. Hope it might help you.

C#:
protected void  RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "CopyPaste")
    {
     RadGrid2.MasterTableView.IsItemInserted = true;
      RadGrid2.Rebind();
      GridDataItem item = (GridDataItem)e.Item;
      GridEditFormInsertItem insertItem = (GridEditFormInsertItem)RadGrid2.MasterTableView.GetInsertItem();//getting insert row
      TextBox txtname = (TextBox)insertItem.FindControl("TextBox2");//acces control in insert form
     txtname.Text = item["Name"].Text;//populate TextBox with corresponding cell value
       }
    }

Thanks,
Princy.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Share this question
or