Hello Team,
I am trying to insert the record using EditFormTemplate of RadGrid. I need to calculate the value based on the one textbox which is in editformtemplate and show the value in another textbox. I can get the controls if I edit the existing records by using grid.MasterTableView.get_insertItem().
How can I get the template controls while adding new records.
Please help..
Thanks,
Vinay
I am trying to insert the record using EditFormTemplate of RadGrid. I need to calculate the value based on the one textbox which is in editformtemplate and show the value in another textbox. I can get the controls if I edit the existing records by using grid.MasterTableView.get_insertItem().
How can I get the template controls while adding new records.
Please help..
Thanks,
Vinay
5 Answers, 1 is accepted
1
Jayesh Goyani
Top achievements
Rank 2
answered on 22 Jul 2014, 07:02 PM
Hello Vinay,
Method 1:
Thanks,
Jayesh Goyani
Method 1:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False" AllowPaging="true" PageSize="10" OnNeedDataSource="RadGrid1_NeedDataSource"> <PagerStyle AlwaysVisible="true" /> <MasterTableView CommandItemDisplay="Top"> <Columns> <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID"> </telerik:GridBoundColumn> </Columns> <EditFormSettings EditFormType="Template"> <FormTemplate> <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </FormTemplate> </EditFormSettings> </MasterTableView></telerik:RadGrid>protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e){ dynamic data = new[] { new { ID = 1, Name ="name1"}, new { ID = 2, Name = "name2"}, new { ID = 3, Name = "name3"}, new { ID = 4, Name = "Name4"}, new { ID = 5, Name ="name5"}}; RadGrid1.DataSource = data;}protected void TextBox1_TextChanged(object sender, EventArgs e){ TextBox TextBox1 = sender as TextBox; GridEditFormItem item = TextBox1.NamingContainer as GridEditFormItem; (item.FindControl("TextBox2") as TextBox).Text = TextBox1.Text;}Thanks,
Jayesh Goyani
zznbilly
commented on 21 Sep 2023, 10:13 AM
| edited
Top achievements
Rank 1
My friend, a lot of "likes" from me :) U r magnificent :) Many regards from Athens-Hellas (Greece) :)
0
Vinay
Top achievements
Rank 1
answered on 23 Jul 2014, 04:58 AM
Hi Jayesh,
Thanks for your reply.
I will implement the same and let you know how it goes on my end.
Thanks,
Vinay
Thanks for your reply.
I will implement the same and let you know how it goes on my end.
Thanks,
Vinay
0
Vinay
Top achievements
Rank 1
answered on 23 Jul 2014, 05:47 AM
Hi Jayesh,
Sorry, but it is not working for me as the value gets to the 0 again as page refreshes as text box contains autopostback property to true.
Can't we do it at client side?
Thanks,
Vinay
Sorry, but it is not working for me as the value gets to the 0 again as page refreshes as text box contains autopostback property to true.
Can't we do it at client side?
Thanks,
Vinay
0
Accepted
Princy
Top achievements
Rank 2
answered on 23 Jul 2014, 06:58 AM
Hi Vinay,
Please try the following code snippet to set a TextBox value from clientside. Please note that the values in the TextBox will not persisted if the grid Rebinds. To restore the values in TextBox you will have to handle them manually.
ASPX:
C#:
JS:
Thanks,
Princy
Please try the following code snippet to set a TextBox value from clientside. Please note that the values in the TextBox will not persisted if the grid Rebinds. To restore the values in TextBox you will have to handle them manually.
ASPX:
<FormTemplate> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </FormTemplate>C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e){ if (e.Item is GridEditableItem && e.Item.IsInEditMode) { GridEditableItem editItem = (GridEditableItem)e.Item; TextBox TextBox1 = (TextBox)editItem.FindControl("TextBox1"); TextBox TextBox2 = (TextBox)editItem.FindControl("TextBox2"); TextBox1.Attributes.Add("onBlur", "return TextChanged(" + TextBox1.ClientID + "," + TextBox2.ClientID + ")"); }}JS:
<script type="text/javascript"> function TextChanged(txt1, txt2) { txt2.value = (txt1.value); }</script>Thanks,
Princy
0
Vinay
Top achievements
Rank 1
answered on 23 Jul 2014, 10:48 AM
Excellent Princy.
Thanks for your reply and it is working like a charm.
Thanks Again.
Vinay
Thanks for your reply and it is working like a charm.
Thanks Again.
Vinay