Alessandro Distefano
Top achievements
Rank 1
Alessandro Distefano
asked on 08 Jan 2010, 02:01 PM
I am a new user of Telerik components and are impressed by their use and the support that is offered.
I have a problem: I have a Radgrid composed GridTemplateColumn inside which there are "asp: TextBox". The user types in these TextBox and a "asp: Button" outside the RadGrid to save what has been edited by the user. Then the server side I have somehow the data entered by the user.
Can you help?
It would be useful to post the code to be used as an example.
Alessandro
I have a problem: I have a Radgrid composed GridTemplateColumn inside which there are "asp: TextBox". The user types in these TextBox and a "asp: Button" outside the RadGrid to save what has been edited by the user. Then the server side I have somehow the data entered by the user.
Can you help?
It would be useful to post the code to be used as an example.
Alessandro
3 Answers, 1 is accepted
0
Hello Alessandro,
I would suggest you to review the following help article:
Accessing cells and rows
I hope this helps,
Martin
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
I would suggest you to review the following help article:
Accessing cells and rows
I hope this helps,
Martin
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Alessandro Distefano
Top achievements
Rank 1
answered on 08 Jan 2010, 03:15 PM
Hi admin,
the help article says:
" When implementing an event handler for an event such as ItemCreated, ItemDataBound, ItemCommand, UpdateCommand, InsertCommand, or DeleteCommand, you can obtain a GridDataItem or GridEditFormItem for the row from the event arguments (e.Item or, in a hierarchical grid, e.Item.OwnerTableView.ParentItem) "
But I do not have this type of event handler; I would have the data entered by the user, with the method:
protected void ButtonSave_Click(object sender, EventArgs e) { .... }
Do not think then that we need to be done post back to radGrid? How can you have the data entered by the user on the server side?
Thank you for the support!
Alessandro
the help article says:
" When implementing an event handler for an event such as ItemCreated, ItemDataBound, ItemCommand, UpdateCommand, InsertCommand, or DeleteCommand, you can obtain a GridDataItem or GridEditFormItem for the row from the event arguments (e.Item or, in a hierarchical grid, e.Item.OwnerTableView.ParentItem) "
But I do not have this type of event handler; I would have the data entered by the user, with the method:
protected void ButtonSave_Click(object sender, EventArgs e) { .... }
Do not think then that we need to be done post back to radGrid? How can you have the data entered by the user on the server side?
Thank you for the support!
Alessandro
0
Hello Alessandro,
The GridTableView.Items property provides a collection of the data items in the table view. To get the EditFormItems you can use the MasterTableView.GetItems(GridItemType.EditFormItem) method. Then use the FindControl() method to get a reference to a specific control placed in the ItemTemplate or EditItemTemplate. Here is a small sample based on this approach:
And the code-behind:
I hope this helps.
Martin
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
The GridTableView.Items property provides a collection of the data items in the table view. To get the EditFormItems you can use the MasterTableView.GetItems(GridItemType.EditFormItem) method. Then use the FindControl() method to get a reference to a specific control placed in the ItemTemplate or EditItemTemplate. Here is a small sample based on this approach:
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateEditColumn="true" AllowMultiRowEdit="true" onprerender="RadGrid1_PreRender"> <MasterTableView AutoGenerateColumns="False" > <Columns> <telerik:GridBoundColumn DataField="ID" Visible="false" ReadOnly="true" /> <telerik:GridTemplateColumn HeaderText="My template column"> <ItemTemplate> <asp:TextBox runat="server" ID="TextBox1" /> </ItemTemplate> <EditItemTemplate> <asp:TextBox runat="server" ID="TextBox2" /> </EditItemTemplate> </telerik:GridTemplateColumn> </Columns> </MasterTableView> </telerik:RadGrid> <asp:Button runat="server" ID="Button1" OnClick="Button1_Click" Text="Set text" />And the code-behind:
DataTable table; protected void Page_Load(object sender, EventArgs e) { table = new DataTable(); table.Columns.Add("ID", typeof(int)); for (int i = 0; i < 5; i++) { table.Rows.Add(i); } } protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { RadGrid1.DataSource = table; } protected void Button1_Click(object sender, EventArgs e) { GridItem[] editedItems = RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem); GridDataItemCollection notEditedItems = RadGrid1.MasterTableView.Items; foreach (GridDataItem item in notEditedItems) { (item.FindControl("TextBox1") as TextBox).Text = item.ItemIndex.ToString(); } foreach (GridEditFormItem item in editedItems) { if (item.IsInEditMode) { (item.FindControl("TextBox2") as TextBox).Text = item.ItemIndex.ToString(); } } } protected void RadGrid1_PreRender(object sender, EventArgs e) { if (!IsPostBack) { foreach (GridDataItem item in RadGrid1.Items) { item.Edit = true; } RadGrid1.Rebind(); } }I hope this helps.
Martin
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.