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

[Solved] Grid Insert

8 Answers 191 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Maher Khalil
Top achievements
Rank 1
Maher Khalil asked on 23 Oct 2009, 08:01 AM

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

Sort by
0
Accepted
Daniel
Telerik team
answered on 23 Oct 2009, 09:11 AM
Hello Maher,

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.
0
Maher Khalil
Top achievements
Rank 1
answered on 23 Oct 2009, 11:23 AM

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

0
Daniel
Telerik team
answered on 28 Oct 2009, 03:31 PM
Hello Maher,

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.
0
Maher Khalil
Top achievements
Rank 1
answered on 03 Nov 2009, 06:49 PM
thank you for replaying
the grid always set the PK column as read only and i have to change it
that is not a problem the question now

1- the grid now show the insert form and take the values but does not insert into the table it just postback and nothing inserted
do i have to write code behind for the insert

2- i need to provide the PK in code behind before insert (autonumber)
<%@ 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> 
 
0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Nov 2009, 05:01 AM
Hello Maher,

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.
0
Maher Khalil
Top achievements
Rank 1
answered on 04 Nov 2009, 09:09 AM
thanks

i need to make the PK column readonly and take other values from the grid and from the code behind give the PK
what event to use and what syntax 

As Example 
on insert event
e.values["PK"]=max_PK+1

0
Accepted
Shinu
Top achievements
Rank 2
answered on 04 Nov 2009, 12:50 PM
Hello Maher Khalil,

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.
0
Maher Khalil
Top achievements
Rank 1
answered on 05 Nov 2009, 08:27 AM
thank you all for the help
 
Shinu Your code was a big help it is brilliant
 a special thanks to you 
Tags
Grid
Asked by
Maher Khalil
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Maher Khalil
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Share this question
or