prashant kamdar
Top achievements
Rank 1
prashant kamdar
asked on 08 Apr 2011, 10:52 AM
i am displaying data inside the telerik grid using sqldatasource which has a select command to join data from 2 tables
now, in that grid i want to have a button, when clicked will add the corresponding row to ANOTHER table alongwith data from a text box (textbox appearing inside the grid row where the button was clicked)
im stuck and need help
now, in that grid i want to have a button, when clicked will add the corresponding row to ANOTHER table alongwith data from a text box (textbox appearing inside the grid row where the button was clicked)
im stuck and need help
<telerik:RadGrid ID="radgridLukkheUsers" runat="server" DataSourceID="lukkheusers" GridLines="None" AutoGenerateColumns="False"> <MasterTableView DataSourceID="lukkheusers"> <Columns> <telerik:GridBoundColumn DataField="displayname" HeaderText="User" SortExpression="displayname" UniqueName="displayname"> </telerik:GridBoundColumn> <telerik:GridButtonColumn ButtonType="PushButton" Text="Add" CommandName="Add"> </telerik:GridButtonColumn> </Columns> </MasterTableView> </telerik:RadGrid>5 Answers, 1 is accepted
0
prashant kamdar
Top achievements
Rank 1
answered on 12 Apr 2011, 07:08 AM
please help
0
Princy
Top achievements
Rank 2
answered on 12 Apr 2011, 08:26 AM
Hello Prashant,
I suppose you want to add RadGrid1's data to a new table when clicking a button in RadGrid1(button for each row in RadGrid1). If this is the case, then one suggestion would be when clicking on that button, get the cell values and then insert the corresponding row to the new table. Sample code is given below.
ASPX:
C#:
Thanks,
Princy.
I suppose you want to add RadGrid1's data to a new table when clicking a button in RadGrid1(button for each row in RadGrid1). If this is the case, then one suggestion would be when clicking on that button, get the cell values and then insert the corresponding row to the new table. Sample code is given below.
ASPX:
<telerik:RadGrid ID="RadGrid1" AutoGenerateColumns="false" runat="server" DataSourceID="SqlDataSource1" OnItemCommand="RadGrid1_ItemCommand"> <MasterTableView DataKeyNames="EmployeeID"> <Columns> <telerik:GridBoundColumn DataField="EmployeeID" UniqueName="EmployeeID"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName"> </telerik:GridBoundColumn> <telerik:GridButtonColumn CommandName="SelectRow" Text="SelectRow"> </telerik:GridButtonColumn> </Columns> </MasterTableView></telerik:RadGrid>C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e) { if (e.CommandName == "SelectRow") { GridDataItem item = (GridDataItem)e.Item; string id = item["EmployeeID"].Text; string name = item["FirstName"].Text; //insert command to add these values to a new table } }Thanks,
Princy.
0
prashant kamdar
Top achievements
Rank 1
answered on 21 Apr 2011, 06:59 AM
thank you
but what i want to do is:
on clicking a button in the grid, the grid will come in edit mode with one more text field (which is not displayed in the grid before) and then clicking on save, the data from all text fields will be saved in another table
can you please guide?
but what i want to do is:
on clicking a button in the grid, the grid will come in edit mode with one more text field (which is not displayed in the grid before) and then clicking on save, the data from all text fields will be saved in another table
can you please guide?
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 Apr 2011, 07:41 AM
Hello,
One suggestion is to add a TextBox control inside EditItemTemplate. You can access the TextBox in the UpdateCommand event like below.
Hope this helps you.
ASPX:
C#:
Thanks,
Princy
One suggestion is to add a TextBox control inside EditItemTemplate. You can access the TextBox in the UpdateCommand event like below.
Hope this helps you.
ASPX:
<Columns> <telerik:GridBoundColumn DataField="FirstName" UniqueName="FirstName"> </telerik:GridBoundColumn> <telerik:GridTemplateColumn> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </EditItemTemplate></telerik:GridTemplateColumn></Columns>C#:
protected void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e) { if (e.Item is GridEditFormItem && e.Item.IsInEditMode) { GridEditFormItem editItem = e.Item as GridEditFormItem; TextBox txt = (TextBox)e.Item.FindControl("TextBox2"); //your query for inserting data into your second table.
} }
Thanks,
Princy
0
prashant kamdar
Top achievements
Rank 1
answered on 21 Apr 2011, 08:11 AM
excellent support!