Hi
i'm new with telerik controls i have some questions about the radGrid
1- i have bound the grid to a sqldatasourse and set the data source insert query set allowautomaticdelete, allowautomaticedit,allowautomaticinsert all to true
now i have edit and delete buttons where is the insert button it is not shown
2- i made a normal link button insted of the insert button and but onclick event for that button
RadGrid1.MasterTableView.InsertItem()
that show an insert form with text box for every column except the primary key it not shown of course the insert fails without the primary key
3- how can i customize the insert form (use checkbox and dropdown insted of textbox)
thanks for the help
8 Answers, 1 is accepted
Straight to your questions:
1. The "Insert" button reside in the command item - set MasterTableView-CommandItemDisplay="Top" to enable it
2. Probably the corresponding column has ReadOnly="true".
3. Please examine the following links:
online demo: Automatic Operations
documentation: Automatic DataSource operations
documentation: Column types
Let me know if you need further assistance.
Best regards,
Daniel
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.
Q1 Solution is perfect thank you
Q2 i tried to bound to Northwind Category table and it is the same show only the other field and not showing the PK
So what is the event that fires before inserting to use it to send the PK value
is there so thing like e.newvalues["ID"]
Q3 Links are very useful and it wil take time to examine
Thank You
Telerik Version 2008.1.415.35
Please post your markup here so I can create a runnable demo for you. Otherwise you can attach the project to regular support ticket and I will modify it on my end.
Regards,
Daniel
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.
| <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %> |
| <%@ Register assembly="Telerik.ReportViewer.WebForms, Version=3.1.9.701, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" namespace="Telerik.ReportViewer.WebForms" tagprefix="telerik" %> |
| <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head runat="server"> |
| <title>Untitled Page</title> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <div> |
| <asp:ScriptManager ID="ScriptManager1" runat="server"> |
| </asp:ScriptManager> |
| <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateDeleteColumn="True" |
| AutoGenerateEditColumn="True" DataSourceID="SqlDataSource1" |
| GridLines="None" Skin="Vista"> |
| <MasterTableView autogeneratecolumns="False" commanditemdisplay="Top" |
| datakeynames="Person_ID" datasourceid="SqlDataSource1"> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridBoundColumn DataField="Person_ID" DataType="System.Int32" |
| HeaderText="Person_ID" SortExpression="Person_ID" UniqueName="Person_ID"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Person_Name" HeaderText="Person_Name" |
| SortExpression="Person_Name" UniqueName="Person_Name"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Age" DataType="System.Int32" |
| HeaderText="Age" SortExpression="Age" UniqueName="Age"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn DataField="Address" HeaderText="Address" |
| SortExpression="Address" UniqueName="Address"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings AllowColumnsReorder="True" |
| ReorderColumnsOnClient="True"> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| <asp:SqlDataSource ID="SqlDataSource1" runat="server" |
| ConnectionString="<%$ ConnectionStrings:Tier %>" |
| DeleteCommand="DELETE FROM [Persons] WHERE [Person_ID] = @Person_ID" |
| InsertCommand="INSERT INTO [Persons] ([Person_ID], [Person_Name], [Age], [Address]) VALUES (@Person_ID, @Person_Name, @Age, @Address)" |
| SelectCommand="SELECT [Person_ID], [Person_Name], [Age], [Address] FROM [Persons]" |
| UpdateCommand="UPDATE [Persons] SET [Person_Name] = @Person_Name, [Age] = @Age, [Address] = @Address WHERE [Person_ID] = @Person_ID"> |
| <DeleteParameters> |
| <asp:Parameter Name="Person_ID" Type="Int32" /> |
| </DeleteParameters> |
| <UpdateParameters> |
| <asp:Parameter Name="Person_Name" Type="String" /> |
| <asp:Parameter Name="Age" Type="Int32" /> |
| <asp:Parameter Name="Address" Type="String" /> |
| <asp:Parameter Name="Person_ID" Type="Int32" /> |
| </UpdateParameters> |
| <InsertParameters> |
| <asp:Parameter Name="Person_ID" Type="Int32" /> |
| <asp:Parameter Name="Person_Name" Type="String" /> |
| <asp:Parameter Name="Age" Type="Int32" /> |
| <asp:Parameter Name="Address" Type="String" /> |
| </InsertParameters> |
| </asp:SqlDataSource> |
| </div> |
| </form> |
| </body> |
| </html> |
You can set the AllowAutomaticInserts property of the RadGrid to true to perform insert without having to write seperate code for Insert in the code behind. Refer to the online documentation to understand better:
Automatic DataSource operations
Thanks
Princy.
One suggestion will be getting the last inserted row value using query as shown in the code library, and setting the Insert parameter of SqlDataSource from code behind (after incrementing the value).
Feel free to share the comments,
Shinu.