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

[Solved] Grid Insert, Update, Delete

1 Answer 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vaughan Gerson
Top achievements
Rank 1
Vaughan Gerson asked on 14 Jul 2009, 11:46 AM
Hi Guys
 I'm having a bit of a problem getting my rad grid to update, Delete, and Insert new records, i'm usnig RadGrid1_NeedDataSource to bind a datasource to the grid, first i'm selecting different query strings from a dropdown list to populate the datasource, this works great..how do i get my grid to insert,update and delete, taking into consideration i'm usig 1 grid for different queries.
i'll paste my code below.

using System; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.HtmlControls; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Xml.Linq; 
using System.Data.SqlClient; 
using Telerik.Web.UI; 
using System.Collections.Generic; 
 
 
public partial class Grid : System.Web.UI.Page 
    string tbName; 
    protected void Page_Load(object sender, EventArgs e) 
    { 
         
        if (Session["ID"] != null
        { 
            tbName = Request["id"].ToString(); 
            if (!Page.IsPostBack) 
            { 
    
                ViewState["tbName"] = tbName; 
            } 
            else 
            { 
 
 
            }   
        } 
 
        else 
        { 
            Response.Redirect("login.aspx"); 
        } 
    } 
 
    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
 
        string sql = @"Select * from " + ViewState["tbName"].ToString() ; 
        SqlConnection oCon = new SqlConnection(DatabaseConnection.ConnectionString); 
        SqlCommand cmd = new SqlCommand(sql, oCon); 
        cmd.CommandType = CommandType.Text; 
        DataTable tblData = new DataTable(); 
        new SqlDataAdapter(cmd).Fill(tblData); 
        RadGrid1.DataSource = tblData; 
    } 
 
    bool isGrouping = false
    protected void RadGrid1_GroupsChanging(object source, GridGroupsChangingEventArgs e) 
    { 
        isGrouping = true
        if (e.Action == GridGroupsChangingAction.Ungroup && RadGrid1.CurrentPageIndex > 0) 
        { 
            isGrouping = false
        } 
    } 
 
 

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Grid.aspx.cs" Inherits="Grid" Title="Untitled Page" %> 
 
<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> 
 
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"
    <style type="text/css"
 
 
.RadGrid_Default 
    border:1px solid #232323; 
 
.RadGrid_Default 
    font:11px/1.4 arial,sans-serif; 
 
.RadGrid_Default 
    background:#d4d0c8; 
    color:#333; 
 
.GroupPanel_Default 
    border-top:1px solid #383838; 
    background:url('mvwres://Telerik.Web.UI, Version=2008.2.826.35, Culture=neutralPublicKeyToken=121fae78165ba3d4/Telerik.Web.UI.Skins.Default.Grid.sprite.gif') repeat-x 0 -400px #1f1f1f; 
    color:#8f8f8f; 
 
.MasterTable_Default 
    background:#fff; 
    border-collapse:separate !important; 
 
.MasterTable_Default 
    font:11px/1.4 arial,sans-serif; 
 
.GridHeader_Default 
    color:#fff; 
    text-decoration:none; 
 
.GridHeader_Default 
    border-bottom:1px solid #010101; 
    background:url('mvwres://Telerik.Web.UI, Version=2008.2.826.35, Culture=neutralPublicKeyToken=121fae78165ba3d4/Telerik.Web.UI.Skins.Default.Grid.headers.gif') repeat-x #434343; 
    padding:10px 6px 10px 11px; 
    text-align:left; 
    font-size:1.3em; 
    font-weight:normal; 
 
        #Table3 
        { 
            width: 681px; 
        } 
         
    .style2 
    { 
        height: 28px; 
    } 
         
    </style> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"
 
    <table style="width: 100%;"
        <tr> 
            <td class="style2"
                </td> 
        </tr> 
        <tr> 
            <td> 
                &nbsp;</td> 
        </tr> 
        <tr> 
            <td> 
                <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True"  
                    AllowPaging="True"  AutoGenerateDeleteColumn="True"  
                    AutoGenerateEditColumn="True" GridLines="None" Skin="Vista"  
                    OnNeedDataSource="RadGrid1_NeedDataSource"  
                    OnGroupsChanging="RadGrid1_GroupsChanging" AllowAutomaticDeletes="True"  
                    AllowAutomaticInserts="True" AllowAutomaticUpdates="True" OnItemUpdated="RadGrid1_ItemUpdated" 
            OnItemDeleted="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted" > 
<HeaderContextMenu> 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</HeaderContextMenu> 
<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> 
<MasterTableView CommandItemDisplay="Top" EditMode ="PopUp" AllowFilteringByColumn="True" > 
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
</MasterTableView> 
 
                    <ClientSettings AllowKeyboardNavigation="True"
                        <Selecting AllowRowSelect="True" /> 
                    </ClientSettings> 
 
<FilterMenu> 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</FilterMenu> 
                </telerik:RadGrid> 
            </td> 
        </tr> 
    </table> 
 
    </asp:Content> 

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 14 Jul 2009, 04:07 PM
Hello Vaughan,

I was able to answer to the support ticket opened on the same matter. Here is a quote of the answer:

Hello Vaughan,

Thank you for contacting us.

Please examine this online help article devoted on the same matter.

Let me know if I can assist you further.

Best regards,
Georgi Krustev
the Telerik team
I will ask you to continue our conversation in the support thread in order to avoid any duplication.

Regards,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Vaughan Gerson
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or