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

[Solved] radgrid insert not inserting using sqldatasource w/ parameters

6 Answers 480 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jon-Jon Kershaw
Top achievements
Rank 2
Jon-Jon Kershaw asked on 19 May 2009, 10:06 PM
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucViewEditSearchEntry.ascx.cs" 
    Inherits="uc_View_Edit_Search_Entry" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<div> 
    <br /> 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
    &nbsp;  
    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> 
    <telerik:RadGrid ID="rgViewEditSearchEntry" runat="server" AllowFilteringByColumn="True" 
        AllowSorting="True" GroupingSettings-CaseSensitive="false" PageSize="20" GridLines="None" 
        AutoGenerateColumns="False" OnPageIndexChanged="rgViewEditSearchEntry_PageIndexChanged" 
        AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowPaging="True" 
        ShowStatusBar="True" OnItemUpdated="rgViewEditSearchEntry_ItemUpdated" OnItemDeleted="rgViewEditSearchEntry_ItemDeleted" 
        OnItemInserted="rgViewEditSearchEntry_ItemInserted" OnPreRender="rgViewEditSearchEntry_PreRender" 
        DataSourceID="SessionDataSource1">  
        <HeaderContextMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </HeaderContextMenu> 
        <PagerStyle Mode="NextPrevAndNumeric" /> 
        <MasterTableView DataKeyNames="Premise_Phone" ShowFooter="False" CommandItemSettings-AddNewRecordText="Add New Contact" 
            CommandItemDisplay="TopAndBottom">  
            <CommandItemSettings AddNewRecordText="Add New Blocked Account"></CommandItemSettings> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridEditCommandColumn UpdateText="Update" UniqueName="EditCommandColumn" 
                    CancelText="Cancel" EditText="Edit">  
                    <HeaderStyle Width="85px"></HeaderStyle> 
                </telerik:GridEditCommandColumn> 
                <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete" /> 
                <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" HeaderText="Id" ReadOnly="True" 
                    SortExpression="Id" UniqueName="Id" FilterControlWidth="20px">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="DNIS" HeaderText="DNIS" SortExpression="DNIS" 
                    UniqueName="DNIS" FilterControlWidth="30px">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Prefix" HeaderText="Prefix" SortExpression="Prefix" 
                    UniqueName="Prefix" FilterControlWidth="30px">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Panel_Code" HeaderText="Panel_Code" SortExpression="Panel_Code" 
                    UniqueName="Panel_Code" FilterControlWidth="30px">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Premise_Phone" HeaderText="Premise_Phone" SortExpression="Premise_Phone" 
                    UniqueName="Premise_Phone">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Toll_Free_Number" HeaderText="Toll_Free_Number" 
                    SortExpression="Toll_Free_Number" UniqueName="Toll_Free_Number">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Date_Blocked" DataType="System.DateTime" HeaderText="Date_Blocked" 
                    SortExpression="Date_Blocked" UniqueName="Date_Blocked">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="CS_Number" HeaderText="CS_Number" SortExpression="CS_Number" 
                    UniqueName="CS_Number">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Comments" HeaderText="Comments" SortExpression="Comments" 
                    UniqueName="Comments">  
                </telerik:GridBoundColumn> 
            </Columns> 
            <EditFormSettings ColumnNumber="3" CaptionFormatString="Edit details for Blocked Acct with ID {0}" 
                CaptionDataField="Id">  
                <FormTableItemStyle Wrap="False"></FormTableItemStyle> 
                <FormCaptionStyle></FormCaptionStyle>  
                <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%" /> 
                <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" Height="110px" 
                    Width="100%" /> 
                <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> 
                <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle> 
                <EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">  
                </EditColumn> 
                <FormTableButtonRowStyle HorizontalAlign="Left"></FormTableButtonRowStyle> 
            </EditFormSettings> 
        </MasterTableView> 
        <GroupingSettings CaseSensitive="False"></GroupingSettings> 
        <FilterMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </FilterMenu> 
    </telerik:RadGrid> 
    <asp:SqlDataSource ID="SessionDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:RxLogConnectionString %>" 
        ProviderName="System.Data.SqlClient" OldValuesParameterFormatString="original_{0}" 
        SelectCommand="SELECT Id, DNIS, Prefix, Panel_Code, Premise_Phone, Toll_Free_Number, Date_Blocked, CS_Number, Comments FROM [BlokedAcc]" 
        DeleteCommand="DELETE FROM [BlokedAcc] WHERE [Id] = Id"   
        InsertCommand="INSERT INTO [BlokedAcc] ([DNIS], [Prefix], [Panel_Code], [Premise_Phone], [Toll_Free_Number], [Date_Blocked], [CS_Number], [Comments]) VALUES (DNIS, Prefix, Panel_Code, Premise_Phone, Toll_Free_Number, Date_Blocked, CS_Number, Comments)" 
        UpdateCommand="UPDATE [BlokedAcc] SET [DNIS] = DNIS, [Prefix] = Prefix, [Panel_Code] = Panel_Code, [Premise_Phone] = Premise_Phone, [Toll_Free_Number] = Toll_Free_Number, [Date_Blocked] = Date_Blocked, [CS_Number] = CS_Number, [Comments] = Comments WHERE [Id] = Id" 
        ConflictDetection="CompareAllValues">  
        <DeleteParameters> 
            <asp:Parameter Name="Id" Type="String" /> 
            <asp:Parameter Name="original_Id" Type="Int64"></asp:Parameter> 
            <asp:Parameter Name="original_DNIS" Type="String"></asp:Parameter> 
            <asp:Parameter Name="original_Prefix" Type="String"></asp:Parameter> 
            <asp:Parameter Name="original_Panel_Code" Type="String"></asp:Parameter> 
            <asp:Parameter Name="original_Premise_Phone" Type="String"></asp:Parameter> 
            <asp:Parameter Name="original_Toll_Free_Number" Type="String"></asp:Parameter> 
            <asp:Parameter Name="original_Date_Blocked" Type="DateTime"></asp:Parameter> 
            <asp:Parameter Name="original_CS_Number" Type="String"></asp:Parameter> 
            <asp:Parameter Name="original_Comments" Type="String"></asp:Parameter> 
        </DeleteParameters> 
        <UpdateParameters> 
            <asp:Parameter Name="Id" Type="Int64" /> 
            <asp:Parameter Name="DNIS" Type="String" /> 
            <asp:Parameter Name="Prefix" Type="String" /> 
            <asp:Parameter Name="Panel_Code" Type="String" /> 
            <asp:Parameter Name="Premise_Phone" Type="String" /> 
            <asp:Parameter Name="Toll_Free_Number" Type="String" /> 
            <asp:Parameter Name="Date_Blocked" Type="DateTime" /> 
            <asp:Parameter Name="CS_Number" Type="String" /> 
            <asp:Parameter Name="Comments" Type="String" /> 
            <asp:Parameter Name="original_Id" Type="Int64" /> 
            <asp:Parameter Name="original_DNIS" Type="String" /> 
            <asp:Parameter Name="original_Prefix" Type="String" /> 
            <asp:Parameter Name="original_Panel_Code" Type="String" /> 
            <asp:Parameter Name="original_Premise_Phone" Type="String" /> 
            <asp:Parameter Name="original_Toll_Free_Number" Type="String" /> 
            <asp:Parameter Name="original_Date_Blocked" Type="DateTime" /> 
            <asp:Parameter Name="original_CS_Number" Type="String" /> 
            <asp:Parameter Name="original_Comments" Type="String" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:Parameter Name="@DNIS" Type="String" /> 
            <asp:Parameter Name="@Prefix" Type="String" /> 
            <asp:Parameter Name="@Panel_Code" Type="String" /> 
            <asp:Parameter Name="@Premise_Phone" Type="String" /> 
            <asp:Parameter Name="@Toll_Free_Number" Type="String" /> 
            <asp:Parameter Name="@Date_Blocked" Type="DateTime" /> 
            <asp:Parameter Name="@CS_Number" Type="String" /> 
            <asp:Parameter Name="@Comments" Type="String" /> 
        </InsertParameters> 
    </asp:SqlDataSource> 
</div> 
 
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using Telerik.Web.UI;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Web.Security;  
using System.Text;  
using System.Data.SqlClient;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
using System.Drawing;  
 
 
public partial class uc_View_Edit_Search_Entry : System.Web.UI.UserControl  
{  
    protected override void OnLoad(EventArgs e)  
    {  
        rgViewEditSearchEntry.DataBind();  
    }  
 
    protected void rgViewEditSearchEntry_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)  
    {  
        rgViewEditSearchEntry.DataBind();  
    }  
 
    protected void rgViewEditSearchEntry_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)  
    {  
        if (e.Exception != null)  
        {  
            e.KeepInEditMode = true;  
            e.ExceptionHandled = true;  
            DisplayMessage(true"Id " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"] + " cannot be updated. Reason: " + e.Exception.Message);  
        }  
        else 
        {  
            DisplayMessage(false"Id " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"] + " updated");  
        }  
    }  
 
    protected void rgViewEditSearchEntry_ItemInserted(object source, GridInsertedEventArgs e)  
    {  
        if (e.Exception != null)  
        {  
            e.ExceptionHandled = true;  
            e.KeepInInsertMode = true;  
            DisplayMessage(true"Id cannot be inserted. Reason: " + e.Exception.Message);  
        }  
        else 
        {  
            DisplayMessage(false"Id inserted");  
        }  
    }  
 
    protected void rgViewEditSearchEntry_ItemDeleted(object source, GridDeletedEventArgs e)  
    {  
        if (e.Exception != null)  
        {  
            e.ExceptionHandled = true;  
            DisplayMessage(true"Id " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"] + " cannot be deleted. Reason: " + e.Exception.Message);  
        }  
        else 
        {  
            DisplayMessage(false"Id " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Id"] + " deleted");  
        }  
    }  
 
    private void DisplayMessage(bool isError, string text)  
    {  
        this.Label1.Font.Bold = true;  
        this.Label1.Visible = true;  
        if (isError)  
        {  
            this.Label1.ForeColor = Color.Red;  
        }  
        else 
        {  
            this.Label1.ForeColor = Color.Green;  
        }  
 
        this.Label1.Text = text;  
    }  
 

????

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 May 2009, 05:25 AM
Hi Jon,

Can you try modifying the InsertCommand as shown below and see whether it is working.

 
 InsertCommand="INSERT INTO [BlokedAcc] ([DNIS], [Prefix], [Panel_Code], [Premise_Phone], [Toll_Free_Number], [Date_Blocked], [CS_Number], [Comments]) VALUES (@DNIS, @Prefix, @Panel_Code, @Premise_Phone, @Toll_Free_Number, @Date_Blocked, @CS_Number, @Comments)"  

Also in the above code you have set the DataKeyName as Premise_Phone. Try setting the DataKeyName as Id.

Shinu
0
Jon-Jon Kershaw
Top achievements
Rank 2
answered on 20 May 2009, 03:48 PM
Id cannot be inserted. Reason: Cannot insert the value NULL into column 'Date_Blocked', table 'RxLog.dbo.BlokedAcc'; column does not allow nulls. INSERT fails. The statement has been terminated.

This is the error that it is passing back.  I have '05/20/2009' as the value in the textbox.  I'm lead to believe that the insert isn't finding the record within the entry form in the masterview because when I remove Date_Blocked from the parameters I get the following error.

Id cannot be inserted. Reason: Cannot insert the value NULL into column 'DNIS', table 'RxLog.dbo.BlokedAcc'; column does not allow nulls. INSERT fails. The statement has been terminated.   Label
0
Tsvetoslav
Telerik team
answered on 25 May 2009, 10:27 AM
Hello Jon-Jon Kershaw,

The names for the insert parameters should come without the @ sign. Please, try modifying them as follows:

        <InsertParameters>    
            <asp:Parameter Name="DNIS" Type="String" />    
            <asp:Parameter Name="Prefix" Type="String" />    
            <asp:Parameter Name="Panel_Code" Type="String" />    
            <asp:Parameter Name="Premise_Phone" Type="String" />    
            <asp:Parameter Name="Toll_Free_Number" Type="String" />    
            <asp:Parameter Name="Date_Blocked" Type="DateTime" />    
            <asp:Parameter Name="CS_Number" Type="String" />    
            <asp:Parameter Name="Comments" Type="String" />    
        </InsertParameters>    
 

and let us know of the result.

Thank you.

Best Regards,
Tsvetoslav
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.
0
Jon-Jon Kershaw
Top achievements
Rank 2
answered on 26 May 2009, 09:28 PM
I've never had any luck with the datasource why of dealing with the radgrids so I decided just to do it in code behind as follows. 
using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using Telerik.Web.UI;  
using System.Collections;  
using System.Configuration;  
using System.Data;  
using System.Web.Security;  
using System.Text;  
using System.Data.SqlClient;  
using System.Web.UI.WebControls.WebParts;  
using System.Web.UI.HtmlControls;  
using System.Drawing;  
 
 
public partial class uc_View_Edit_Search_Entry : System.Web.UI.UserControl  
{  
    protected override void OnLoad(EventArgs e)  
    {  
        DataTable dtTable = new DataTable();  
        string conn = ConfigurationManager.ConnectionStrings["RxLogConnectionString"].ToString();  
        SqlDataAdapter sqladp = new SqlDataAdapter();  
        SqlConnection sqlconn = new SqlConnection(conn);  
        sqlconn.Open();  
        try 
        {  
            string selectQuery = "SELECT Id, DNIS, Prefix, Panel_Code, Premise_Phone, Toll_Free_Number, Date_Blocked, CS_Number, Comments FROM [BlokedAcc]";  
            sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);  
            sqladp.Fill(dtTable);  
            rgViewEditSearchEntry.DataSource = dtTable;  
          
        }  
        finally 
        {  
            sqlconn.Close();  
        }  
    }  
 
    protected void rgViewEditSearchEntry_PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)  
    {  
        rgViewEditSearchEntry.DataBind();  
    }  
 
    protected void rgViewEditSearchEntry_ItemCommand(object source, GridCommandEventArgs e)  
    {  
        DataTable dtTable = new DataTable();  
        string conn = ConfigurationManager.ConnectionStrings["RxLogConnectionString"].ToString();  
        SqlDataAdapter sqladp = new SqlDataAdapter();  
        SqlConnection sqlconn = new SqlConnection(conn);  
        SqlCommand sqlcmd = new SqlCommand();  
        if (e.CommandName == RadGrid.PerformInsertCommandName)  
        {  
            GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;  
            string DNIS = (insertedItem["DNIS"].Controls[0] as TextBox).Text;  
            string Prefix = (insertedItem["Prefix"].Controls[0] as TextBox).Text;  
            string Panel_Code = (insertedItem["Panel_Code"].Controls[0] as TextBox).Text;  
            string Premise_Phone = (insertedItem["Premise_Phone"].Controls[0] as TextBox).Text;  
            string Toll_Free_Number = (insertedItem["Toll_Free_Number"].Controls[0] as TextBox).Text;  
            string Date_Blocked = (insertedItem["Date_Blocked"].Controls[0] as TextBox).Text;  
            string CS_Number = (insertedItem["CS_Number"].Controls[0] as TextBox).Text;  
            string Comments = (insertedItem["Comments"].Controls[0] as TextBox).Text;  
            try 
            {  
                sqlconn.Open();  
                string insertQuery = "INSERT INTO [BlokedAcc] ([DNIS], [Prefix], [Panel_Code], [Premise_Phone], [Toll_Free_Number], [CS_Number], [Comments]) VALUES ('" + DNIS + "','" + Prefix + "','" + Panel_Code + "','" + Premise_Phone + "','" + Toll_Free_Number + "','" + CS_Number + "','" + Comments + "')";  
                sqlcmd.CommandText = insertQuery;  
                sqlcmd.Connection = sqlconn;  
                sqlcmd.ExecuteNonQuery();  
                string selectQuery = "SELECT Id, DNIS, Prefix, Panel_Code, Premise_Phone, Toll_Free_Number, Date_Blocked, CS_Number, Comments FROM [BlokedAcc]";  
                sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);  
                sqladp.Fill(dtTable);  
                rgViewEditSearchEntry.DataSource = dtTable;  
                sqlconn.Close();  
            }  
            catch (Exception ex)  
            {  
                rgViewEditSearchEntry.Controls.Add(new LiteralControl("Unable to insert Employee. Reason: " + ex.Message));  
            }  
            rgViewEditSearchEntry.MasterTableView.IsItemInserted = false;  
            rgViewEditSearchEntry.DataBind();  
            e.Canceled = true;  
        }  
        else if (e.CommandName == RadGrid.UpdateCommandName)  
        {  
            GridEditableItem editedItem = e.Item as GridEditableItem;  
 
            string Id = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["Id"].ToString();  
            string DNIS = (editedItem["DNIS"].Controls[0] as TextBox).Text;  
            string Prefix = (editedItem["Prefix"].Controls[0] as TextBox).Text;  
            string Panel_Code = (editedItem["Panel_Code"].Controls[0] as TextBox).Text;  
            string Premise_Phone = (editedItem["Premise_Phone"].Controls[0] as TextBox).Text;  
            string Toll_Free_Number = (editedItem["Toll_Free_Number"].Controls[0] as TextBox).Text;  
            string Date_Blocked = (editedItem["Date_Blocked"].Controls[0] as RadTextBox).Text;  
            string CS_Number = (editedItem["CS_Number"].Controls[0] as TextBox).Text;  
            string Comments = (editedItem["Comments"].Controls[0] as TextBox).Text;  
            try 
            {  
                sqlconn.Open();  
                string updateQuery = "UPDATE [BlokedAcc] SET [DNIS] = '" + DNIS + "', [Prefix] = '" + Prefix + "', [Panel_Code] = '" + Panel_Code + "', [Premise_Phone] = '" + Premise_Phone + "', [Toll_Free_Number] = '" + Toll_Free_Number + "', [Date_Blocked] = '" + Date_Blocked + "', [CS_Number] = '" + CS_Number + "', [Comments] = '" + Comments + "' WHERE [Id] = '" + Id + "'";  
                sqlcmd.CommandText = updateQuery;  
                sqlcmd.Connection = sqlconn;  
                sqlcmd.ExecuteNonQuery();  
                string selectQuery = "SELECT Id, DNIS, Prefix, Panel_Code, Premise_Phone, Toll_Free_Number, Date_Blocked, CS_Number, Comments FROM [BlokedAcc]";  
                sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);  
                sqladp.Fill(dtTable);  
                rgViewEditSearchEntry.DataSource = dtTable;  
                sqlconn.Close();  
            }  
            catch (Exception ex)  
            {  
                rgViewEditSearchEntry.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));  
 
            }  
            rgViewEditSearchEntry.EditIndexes.Clear();  
            rgViewEditSearchEntry.DataBind();  
            e.Canceled = true;  
        }  
        else if (e.CommandName == RadGrid.DeleteCommandName)  
        {  
            GridDataItem item = (GridDataItem)e.Item;  
            string Id = item.OwnerTableView.DataKeyValues[item.ItemIndex]["Id"].ToString();  
            try 
            {  
                sqlconn.Open();  
                string deleteQuery = "DELETE FROM [BlokedAcc] WHERE [Id] ='" + Id + "'";  
                sqlcmd.CommandText = deleteQuery;  
                sqlcmd.Connection = sqlconn;  
                sqlcmd.ExecuteNonQuery();  
                string selectQuery = "SELECT Id, DNIS, Prefix, Panel_Code, Premise_Phone, Toll_Free_Number, Date_Blocked, CS_Number, Comments FROM [BlokedAcc]";  
                sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);  
                sqladp.Fill(dtTable);  
                rgViewEditSearchEntry.DataSource = dtTable;  
                sqlconn.Close();  
            }  
            catch (Exception ex)  
            {  
                rgViewEditSearchEntry.Controls.Add(new LiteralControl("Unable to delete Id. Reason: " + ex.Message));  
                e.Canceled = true;  
            }  
        }  
    }  
}  
 
 
 
 
 
 
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucViewEditSearchEntry.ascx.cs" 
    Inherits="uc_View_Edit_Search_Entry" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<div> 
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> 
    <telerik:RadGrid ID="rgViewEditSearchEntry" runat="server" AllowFilteringByColumn="True" 
        EnableLinqExpressions="False" AllowSorting="True" GroupingSettings-CaseSensitive="false" 
        PageSize="20" GridLines="None" AutoGenerateColumns="False" AllowAutomaticDeletes="True" 
        AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowPaging="True" 
        ShowStatusBar="True" OnPageIndexChanged="rgViewEditSearchEntry_PageIndexChanged" 
        OnItemCommand="rgViewEditSearchEntry_ItemCommand">  
        <HeaderContextMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </HeaderContextMenu> 
        <PagerStyle Mode="NextPrevAndNumeric" /> 
        <MasterTableView DataKeyNames="Id" ShowFooter="False" CommandItemSettings-AddNewRecordText="Add New Contact" 
            CommandItemDisplay="TopAndBottom">  
            <CommandItemSettings AddNewRecordText="Add New Blocked Account"></CommandItemSettings> 
            <RowIndicatorColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn> 
                <HeaderStyle Width="20px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <telerik:GridTemplateColumn UniqueName="EditCommandColumn" ItemStyle-Width="16px" 
                    AllowFiltering="false">  
                    <HeaderStyle Width="16px" /> 
                    <ItemTemplate> 
                        <asp:ImageButton ID="imgbtnEdit" Width="14px" ToolTip="Edit Contact" runat="server" 
                            CommandName="Edit" ImageUrl="../images/magnifying.jpg" /> 
                    </ItemTemplate> 
                    <ItemStyle Width="16px"></ItemStyle> 
                </telerik:GridTemplateColumn> 
                <telerik:GridTemplateColumn UniqueName="DeleteColumn" ItemStyle-Width="16px" AllowFiltering="false">  
                    <HeaderStyle Width="16px" /> 
                    <ItemTemplate> 
                        <asp:ImageButton ID="imgbtnDelete" Width="14px" ToolTip="Delete Contact" runat="server" 
                            CommandName="Delete" ImageUrl="../images/recycle.jpg" OnClientClick="javascript:if(!confirm('This action will delete the selected contact. Are you sure?')){return false;}" /> 
                    </ItemTemplate> 
                    <ItemStyle Width="16px"></ItemStyle> 
                </telerik:GridTemplateColumn> 
                <telerik:GridBoundColumn DataField="Id" DataType="System.Int32" HeaderText="Id" ReadOnly="True" 
                    SortExpression="Id" UniqueName="Id" FilterControlWidth="20px">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="DNIS" HeaderText="DNIS" SortExpression="DNIS" 
                    UniqueName="DNIS" FilterControlWidth="30px">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Prefix" HeaderText="Prefix" SortExpression="Prefix" 
                    UniqueName="Prefix" FilterControlWidth="30px">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Panel_Code" HeaderText="Panel_Code" SortExpression="Panel_Code" 
                    UniqueName="Panel_Code" FilterControlWidth="30px">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Premise_Phone" HeaderText="Premise_Phone" SortExpression="Premise_Phone" 
                    UniqueName="Premise_Phone">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Toll_Free_Number" HeaderText="Toll_Free_Number" 
                    SortExpression="Toll_Free_Number" UniqueName="Toll_Free_Number">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Date_Blocked" DataType="System.DateTime" HeaderText="Date_Blocked" 
                    SortExpression="Date_Blocked" UniqueName="Date_Blocked">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="CS_Number" HeaderText="CS_Number" SortExpression="CS_Number" 
                    UniqueName="CS_Number">  
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn DataField="Comments" HeaderText="Comments" SortExpression="Comments" 
                    UniqueName="Comments">  
                </telerik:GridBoundColumn> 
            </Columns> 
            <EditFormSettings ColumnNumber="3" CaptionFormatString="Edit details for Blocked Acct with ID {0}" 
                CaptionDataField="Id">  
                <EditColumn UniqueName="EditCommandColumn1">  
                </EditColumn> 
                <FormTemplate> 
                    <asp:Table ID="tbSingleEntry" runat="server">  
                        <asp:TableRow> 
                            <asp:TableCell ColumnSpan="2" HorizontalAlign="center">  
                                <asp:Label ID="lblHeaderTitle" runat="server" Text="Single Entry Block Account"></asp:Label> 
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell> 
                                <asp:Label ID="lblDNIS" runat="server" Text="DNIS:"></asp:Label> 
                            </asp:TableCell> 
                            <asp:TableCell> 
                                <asp:TextBox ID="txtDNIS" runat="server"></asp:TextBox> 
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell> 
                                <asp:Label ID="lblPrefix" runat="server" Text="Prefix:"></asp:Label> 
                            </asp:TableCell> 
                            <asp:TableCell> 
                                <asp:TextBox ID="txtPrefix" runat="server"></asp:TextBox> 
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell> 
                                <asp:Label ID="lblPanelCode" runat="server" Text="Panel Code:"></asp:Label> 
                            </asp:TableCell> 
                            <asp:TableCell> 
                                <asp:TextBox ID="txtPanelCode" runat="server"></asp:TextBox> 
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell> 
                                <asp:Label ID="lblPremisePhone" runat="server" Text="Premise Phone:"></asp:Label> 
                            </asp:TableCell> 
                            <asp:TableCell> 
                                <asp:TextBox ID="txtPremisePhone" runat="server"></asp:TextBox> 
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell> 
                                <asp:Label ID="lblTollFreeNumber" runat="server" Text="Toll Free Number:"></asp:Label> 
                            </asp:TableCell> 
                            <asp:TableCell> 
                                <asp:TextBox ID="txtTollFreeNum" runat="server"></asp:TextBox> 
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell> 
                                <asp:Label ID="lblDateBlocked" runat="server" Text="Date Blocked:"></asp:Label> 
                            </asp:TableCell> 
                            <asp:TableCell> 
                            <telerik:RadDatePicker FocusedDate='<%#DateTime.Now %>' ID="txtDateBlocked" runat="server" ReadOnly="true"    />                                                        
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell> 
                                <asp:Label ID="lblCSNumber" runat="server" Text="CS Number:"></asp:Label> 
                            </asp:TableCell> 
                            <asp:TableCell> 
                                <asp:TextBox ID="txtCSNumber" runat="server"></asp:TextBox> 
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell> 
                                <asp:Label ID="lblComments" runat="server" Text="Comments:"></asp:Label> 
                            </asp:TableCell> 
                            <asp:TableCell> 
                                <asp:TextBox ID="txtComments" runat="server"></asp:TextBox> 
                            </asp:TableCell> 
                        </asp:TableRow> 
                        <asp:TableRow> 
                            <asp:TableCell>          
                            </asp:TableCell> 
                            <asp:TableCell> 
                                <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                                    runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>  
                                </asp:Button>&nbsp;<asp:Button CausesValidation="false" ID="btnEdit" Text="EditContact" 
                                    runat="server" CommandName="EditContact"></asp:Button> 
                                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" 
                                    CommandName="Cancel"></asp:Button></td>  
                            </asp:TableCell> 
                        </asp:TableRow> 
                    </asp:Table> 
                </FormTemplate> 
            </EditFormSettings> 
            <NoRecordsTemplate> 
                No Records</NoRecordsTemplate> 
        </MasterTableView> 
        <GroupingSettings CaseSensitive="False"></GroupingSettings> 
        <FilterMenu EnableTheming="True">  
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
        </FilterMenu> 
    </telerik:RadGrid> 
</div> 
 
0
Accepted
Tsvetoslav
Telerik team
answered on 27 May 2009, 12:04 PM
Hello Jon-Jon Kershaw,

For more complex operations such as edit/update/insert you need to use Advanced data binding as opposed to Simple data binding. Therefore, you have to:
 
1. move your code in the Page_Load event to the grid's NeedDataSource event.
2. Remove the databinding statement from the OnPageIndexChanged event handler.
3. Remove the databinding code from the grid's ItemCommand event, namely the following lines:

   
                string selectQuery = "SELECT Id, DNIS, Prefix, Panel_Code, Premise_Phone, Toll_Free_Number, Date_Blocked, CS_Number, Comments FROM [BlokedAcc]";     
                sqladp.SelectCommand = new SqlCommand(selectQuery, sqlconn);     
                sqladp.Fill(dtTable);     
                rgViewEditSearchEntry.DataSource = dtTable;    
 

I hope this information helps.


Best Regards,
Tsvetoslav
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.
0
Jon-Jon Kershaw
Top achievements
Rank 2
answered on 05 Jun 2009, 06:52 PM
yeah that is what i ended up doing.

thanks.
Tags
Grid
Asked by
Jon-Jon Kershaw
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Jon-Jon Kershaw
Top achievements
Rank 2
Tsvetoslav
Telerik team
Share this question
or