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

RadGrid auto update not working

1 Answer 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kenyon
Top achievements
Rank 1
Kenyon asked on 04 Dec 2013, 12:54 AM
Hi there,  I tried using the following example to create a simple grid with auto CRUD.  It looks good but when I click the "update" button the edited fields just reset and nothing else happens.

http://www.telerik.com/community/code-library/aspnet-ajax/grid/automatic-operations-with-sqldatasource-control.aspx

I've had to programmatically add the datasource as my app is rocking a legacy connection string encription routine.

Here's my ASP page:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Edit_GovernanceContacts.aspx.vb"
    Inherits="APSubmission.Edit_GovernanceContacts" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register TagPrefix="uc1" TagName="Menu" Src="Menu.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
    <title>Submission System</title>
</head>
<body style="background-color: #f2ffff">
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <uc1:Menu ID="Menu1" runat="server"></uc1:Menu>
    </div>
    <div style="padding: 10px 0 0 10px">
        Edit Governance Contacts
        <telerik:RadGrid ID="gridContacts" runat="server" AllowAutomaticDeletes="True" EnableAJAX="True"
            AllowAutomaticInserts="True" AllowAutomaticUpdates="True" Skin="WebBlue">
            <MasterTableView AutoGenerateColumns="False" DataKeyNames="recID" CommandItemDisplay="TopAndBottom">
                <EditFormSettings>
                    <EditColumn UniqueName="EditCommandColumn"></EditColumn>
                </EditFormSettings>
                <Columns>
                    <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" ButtonType="imagebutton" />
                    <telerik:GridBoundColumn DataField="recID"
                        FilterControlAltText="Filter columnID column" HeaderText="ID"
                        UniqueName="recID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="submissionSetID"
                        FilterControlAltText="Filter columnSubmissionSet column"
                        HeaderText="Submission Set ID" UniqueName="submissionSetID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="contactName"
                        FilterControlAltText="Filter columnContactName column"
                        HeaderText="Contact Name" UniqueName="contactName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="addDate" DataType="System.DateTime"
                        FilterControlAltText="Filter columnAddDate column" HeaderText="Add Date"
                        ReadOnly="True" UniqueName="addDate">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="addWho"
                        FilterControlAltText="Filter columnAddWho column" HeaderText="Add Who"
                        ReadOnly="True" UniqueName="addWho">
                    </telerik:GridBoundColumn>
                    <telerik:GridButtonColumn UniqueName="ButtonColumn" Text="Delete" CommandName="Delete"
                        ButtonType="LinkButton"/>
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>


And the code behind to create the datasource:
Protected Sub gridContacts_NeedDataSource(sender As Object, e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gridContacts.NeedDataSource       
        Dim myDataSource As New SqlDataSource
 
        myDataSource.ConnectionString = _functions.GetConnectionString()
        myDataSource.DeleteCommand = "delete GovernanceContact where recID = @recID"
        myDataSource.InsertCommand = "insert GovernanceContact (submissionSetID, contactName, addDate, addWho) values @submissionSetID, @contactName, @addDate, @addWho)"
        myDataSource.SelectCommand = "select * from GovernanceContact where submissionSetID = @submissionSetID"
        myDataSource.UpdateCommand = "update GovernanceContact set contactName = @contactName where recID = @recID"
 
        myDataSource.DeleteParameters.Add("recID", DbType.Int32)
 
        myDataSource.InsertParameters.Add("submissionSetID", DbType.Int32, _editSubmissionSetID)
        myDataSource.InsertParameters.Add("contactName", DbType.String)
        myDataSource.InsertParameters.Add("addDate", DbType.DateTime)
        myDataSource.InsertParameters.Add("addWho", DbType.String)
 
        myDataSource.SelectParameters.Add("submissionSetID", DbType.Int32, _editSubmissionSetID)
 
        myDataSource.UpdateParameters.Add("contactName", DbType.String)
        myDataSource.UpdateParameters.Add("recID", DbType.Int32)
 
        gridContacts.DataSource = myDataSource
        gridContacts.MasterTableView.DataSource = myDataSource
    End Sub

I'm obviously doing something wrong, but I just don't know what it is.

Thanks for any help you can provide,
Kenyon.

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 06 Dec 2013, 03:31 PM
Hello Kenyon,

When using automaric CRUD operations you need to bind RadGrid to a declarative data source using the DataSourceID property. Also in order for the automatic operations to work properly the insert, update and delete parameters should be configured for the data source.

An example of how this could be achieved is shown in this article. There is also an online demo illustrating this functionality here.

Regards,
Viktor Tachev
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Kenyon
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or