This is a migrated thread and some comments may be shown as answers.
Insert not working!
1 Answer 91 Views
This is a migrated thread and some comments may be shown as answers.
sayak
Top achievements
Rank 1
sayak asked on 31 Dec 2008, 05:00 PM
Here is what I gave. Can you please direct me to a article that will help me.

Scenario:
Have 3 different layers. (DAL, BLL and UI)
Using objectdatesource at UI layer.
RadGrid's datasource is assigned at design time.
Able to edit data using WebuserControl.
added "add new record" at commanditem to insert.
But it's not doing anything.

No form or user control is showing up. Can you tell me what am I missing. How to tie this event to show the usercontrol in insert mode or something.

I read the topic where in usercontrol has been used. But got an error in :
<asp:button id="btnUpdate" text="Update" runat="server" CommandName="Update" Visible='<%# !(DataItem is Telerik.Web.UI.GridInsertionObject) %>'></asp:button>
            <asp:button id="btnInsert" text="Insert" runat="server" CommandName="PerformInsert" Visible='<%# DataItem is Telerik.Web.UI.GridInsertionObject %>'></asp:button>


Help will be greatly appreciated.

-Sayak

1 Answer, 1 is accepted

Sort by
0
Kevin Babcock
Top achievements
Rank 1
answered on 02 Jan 2009, 02:35 PM
Hi Sayak,

Here is a quick example showing how to use the RadGrid with an ObjectDataSource. You will, of course, need to write your own select/insert/update/delete logic for the DataObject class, but this should give you an idea of how to proceed.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Telerik.Examples._Default" %> 
 
<%@ 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>Example</title> 
</head> 
<body> 
    <form id="form1" runat="server"
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" /> 
         
        <telerik:RadGrid ID="RadGrid1" runat="server" 
            AllowAutomaticInserts="True" 
            AutoGenerateColumns="False" 
            DataSourceID="ObjectDataSource1"
            <MasterTableView 
                CommandItemDisplay="TopAndBottom" 
                DataKeyNames="ID"
                <Columns> 
                    <telerik:GridNumericColumn 
                        DataField="ID" 
                        HeaderText="ID">                         
                    </telerik:GridNumericColumn> 
                    <telerik:GridBoundColumn 
                        DataField="Value" 
                        HeaderText="Value"
                    </telerik:GridBoundColumn> 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid>       
             
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server"  
            DataObjectTypeName="Telerik.Examples.Item"  
            InsertMethod="Insert"   
            SelectMethod="Select"  
            TypeName="Telerik.Examples.ItemDataSource"
        </asp:ObjectDataSource>      
         
    </form> 
</body> 
</html> 
 

using System.Collections.Generic; 
using System.ComponentModel; 
 
namespace Telerik.Examples 
    [DataObject] 
    public class ItemDataSource 
    { 
        [DataObjectMethod(DataObjectMethodType.Select, true)] 
        public IEnumerable<Item> Select() 
        { 
            var items = new Item[]{ 
                new Item { ID=1, Value="Something" }, 
                new Item { ID=2, Value="Something Else" } 
            }; 
            return items; 
        } 
 
        [DataObjectMethod(DataObjectMethodType.Insert, true)] 
        public void Insert(Item item) 
        { 
            // Add insert logic here 
        } 
 
        [DataObjectMethod(DataObjectMethodType.Update, true)] 
        public void Update(Item item) 
        { 
            // Add update logic here 
        } 
 
        [DataObjectMethod(DataObjectMethodType.Delete, true)] 
        public void Delete(Item item) 
        { 
            // Add delete logic here 
        } 
    } 
 
    public class Item 
    { 
        public int ID { getset; } 
        public string Value { getset; } 
    } 
 

I hope this helps. If you have further questions, please let me know.

Regards,
Kevin Babcock
Tags
Grid
Asked by
sayak
Top achievements
Rank 1
Answers by
Kevin Babcock
Top achievements
Rank 1
Share this question
or