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

[Solved] ADD Copy button in Editmode=EditForms

4 Answers 208 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amit Lamba
Top achievements
Rank 1
Amit Lamba asked on 29 Apr 2008, 04:45 PM
Hi Telerik Team,

I want copy the some textbox fields data into another text fields using button click or check box click event when datagrid Editemode="EditForms".
how can i keep copy button or check box when edit mode = editforms in datagrid.

pls let me know,how to slove this issue.

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 30 Apr 2008, 11:49 AM
Hi Amit,

Design your custom edit form using FormTemplate. Place the Copy button inside the edit form as shown below.

ASPX:
<EditFormSettings EditFormType="Template" > 
 <FormTemplate> 
     <asp:TextBox ID="TextBox3"  Text='<%#Eval("Name") %>' runat="server"></asp:TextBox> 
     <asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("Reg") %>' ></asp:TextBox> 
     <asp:Button ID="Button2" runat="server" Text="Copy" OnClick="Button2_Click1" /> 
 </FormTemplate> 
</EditFormSettings> 


CS:
protected void Button2_Click1(object sender, EventArgs e)  
    {  
        foreach (GridEditFormItem EditItem in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem))  
        {  
            TextBox txtbx3 = (TextBox)EditItem.FindControl("TextBox3");  
            TextBox txtbx2 = (TextBox)EditItem.FindControl("TextBox2");  
        }  
     }   


Thanks
Princy.
0
Amit Lamba
Top achievements
Rank 1
answered on 08 May 2008, 06:22 PM

Hi Princy,

Thanks for your reply.still i am getting problem in this issue

if i try EditFormType="Template",i am not showing anytext boxes when i click the edit button in the grid.

here i am sending code sample,i want copy the phonecolumn data to shipphone column when editmode ="editforms" and want keep check box or copybutton in edit forms.


 <
rad:RadGrid ID="radCustomerGrid" runat="server" AllowFilteringByColumn="True" EnableAJAX="True" GridLines="None" AutoGenerateColumns ="False" HeaderStyle-HorizontalAlign ="Left"Width ="949px" needdatasource="radCustomerGrid_NeedDataSource" onprerender="radCustomerGrid_PreRender" oninit="radCustomerGrid_Init" Skin="Mac" FilterItemStyle-HorizontalAlign ="Left" meta:resourcekey="radCustomerGridResource1"

onitemcommand="radCustomerGrid_ItemCommand">
<
PagerStyle Mode= "NextPrevAndNumeric" />

<

MasterTableView AutoGenerateColumns="False" Width ="100%" CommandItemDisplay ="Top" DataKeyNames ="CustomerID" ><CommandItemSettings AddNewRecordText="Add new Customer" RefreshText="Refresh Customer list" />
<Columns>
<rad:GridHyperLinkColumn DataNavigateUrlFields= "CustomerID" Text ="ViewDetail" ItemStyle-HorizontalAlign="Center" AllowFiltering ="false" ItemStyle-Font-Underline="true" ItemStyle-Font-Bold ="true" FooterStyle-ForeColor ="Blue" DataNavigateUrlFormatString ="EditCustomerData.aspx?CustomerID={0}" ></rad:GridHyperLinkColumn>

<rad:GridEditCommandColumn ButtonType="ImageButton" UpdateImageUrl= "../Images/Update.gif" ItemStyle-HorizontalAlign ="Center" HeaderText ="Edit" EditImageUrl="../Images/Edit.gif" InsertImageUrl= "../Images/Update.gif" CancelImageUrl="../Images/Cancel.gif" UniqueName="EditCommandColumn"></rad:GridEditCommandColumn>

<rad:GridButtonColumn ConfirmText="Delete this Customer?" UniqueName="DeleteColumn" CommandName ="Delete" HeaderText= "Delete" ItemStyle-HorizontalAlign="Center" Text ="Delete" ImageUrl="../Images/Delete.gif" ButtonType="ImageButton"></rad:GridButtonColumn>

<rad:GridBoundColumn DataField="CustomerID" DataType="System.Int32" HeaderText="CustomerID" SortExpression="CustomerID" UniqueName="CustomerID" Visible ="false"></rad:GridBoundColumn>

 <rad:GridBoundColumn DataField="UserID" DataType="System.Int32" EditFormColumnIndex ="1"HeaderText="UserID" SortExpression="UserID" UniqueName="UserID" Visible ="false">

<
rad:GridTemplateColumn DataField ="Name" HeaderText="Company Name" SortExpression ="Name" UniqueName="Name" ItemStyle-Wrap="true" ItemStyle-HorizontalAlign="Left" EditFormColumnIndex ="0">

<EditItemTemplate>
 <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name") %>'></asp:TextBox><asp:RequiredFieldValidator ID="nameValidator" ErrorMessage =" * " ControlToValidate ="txtName" runat ="server" ></asp:RequiredFieldValidator>
</
EditItemTemplate>

<ItemTemplate>
<asp:Label id="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
</ItemTemplate>
</rad:GridTemplateColumn>
<
rad:GridBoundColumn DataField="GroupID" DataType="System.Int32" EditFormColumnIndex ="2"HeaderText="GroupID" SortExpression="GroupID" UniqueName="GroupID" Visible ="false">
</rad:GridBoundColumn>

<rad:GridTemplateColumn DataField ="Phone" HeaderText="Phone" SortExpression ="Phone" UniqueName="Phone" Visible="false" EditFormColumnIndex ="0">
    <EditItemTemplate>

    <asp:TextBox ID="txtPhone" runat="server" Text='<%# Bind("Phone") %    >'>    </asp:TextBox><asp:RequiredFieldValidator ID="PhoneValidator"     ErrorMessage     ="* " ControlToValidate ="txtPhone" runat ="server" ></asp:RequiredFieldValidator>
    </EditItemTemplate> 
    <ItemTemplate>
        <asp:Label id="lblPhone" runat="server" Text='<%# Eval("Phone") %>'></asp:Label>
    </ItemTemplate>
</rad:GridTemplateColumn>

<rad:GridTemplateColumn DataField ="ShipPhone" HeaderText="ShipPhone" SortExpression ="ShipPhone" UniqueName="ShipPhone" Visible="false" EditFormColumnIndex ="2">

<EditItemTemplate>

<asp:TextBox ID="txtShipPhone" runat="server" Text='<%# Bind("ShipPhone") %>'></asp:TextBox>

<asp:RequiredFieldValidator ID="ShipPhoneValidator" ErrorMessage =" * " ControlToValidate ="txtShipPhone" runat ="server" ></asp:RequiredFieldValidator>

</EditItemTemplate>

<ItemTemplate>
<asp:Label id="lblShipPhone" runat="server" Text='<%# Eval("ShipPhone") %>'></asp:Label>
</ItemTemplate>
</rad:GridTemplateColumn>

<EditFormSettings

ColumnNumber="3" >
<FormMainTableStyle CellSpacing="0" CellPadding="0"></EditColumn>
</EditFormSettings>

<PagerStyle Mode="NextPrevNumericAndAdvanced" />
</
MasterTableView>
</
rad:RadGrid>

0
Sebastian
Telerik team
answered on 09 May 2008, 06:25 AM
Hello Amit,

When you use FormTemplate custom edit form you will need to define the actual structure of the template in order to display the edit form. See this online demo for more info on the subject:

http://www.telerik.com/demos/aspnet/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultCS.aspx

If you choose auto-generated EditForms mode, consider the suggestion posted by Princy and modify it if necessary. General information about how to access cells and rows in RadGrid and what is the relation between the data item and the edited item when choosing EditMode = "EditForms" you can find in these resources:

http://www.telerik.com/demos/aspnet/Grid/Examples/Programming/AccessingCellsAndRows/DefaultCS.aspx
http://www.telerik.com/help/aspnet/grid/?grdeditforms.html

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Princy
Top achievements
Rank 2
answered on 09 May 2008, 12:02 PM
Hi Amit,

Try the following code snippet.

CS:
protected void Copybtn_Click(object sender, EventArgs e)  
    {  
        foreach (GridEditFormItem EditItem in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem))  
        {  
            TextBox txtPhone = (TextBox)EditItem["Phone"].FindControl("txtPhone");  
            TextBox txtShip = (TextBox)EditItem["ShipPhone"].FindControl("txtShipPhone");  
            txtShip.Text = txtPhone.Text.ToString();  
        }  
   } 


Thanks
Princy.
Tags
Grid
Asked by
Amit Lamba
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Amit Lamba
Top achievements
Rank 1
Sebastian
Telerik team
Share this question
or