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

No Return Values from Edit form

2 Answers 37 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Falk
Top achievements
Rank 1
Falk asked on 11 Aug 2010, 06:56 PM
I have a problem with geting vaules form the Edit / Popup Form.
The underlying datasource is an Object.

I can Insert the values in the form, but my code gets only emtpy values.

What can be wrong

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Arbeitsprofile.aspx.cs" Inherits="Web.Stammdaten.Arbeitsprofile" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <telerik:RadAjaxManager ID="AjaxManager" runat="server" 
                DefaultLoadingPanelID="AjaxLoadingPanel" EnableHistory="True">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="grdArbeitsprofile">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="grdArbeitsprofile" 
                        LoadingPanelID="AjaxLoadingPanel" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
    <telerik:RadAjaxLoadingPanel ID="AjaxLoadingPanel" runat="server" Skin="Default" 
                Transparency="70">
    </telerik:RadAjaxLoadingPanel
    <telerik:RadGrid ID="grdArbeitsprofile" runat="server" AllowSorting="True" 
        AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True" GridLines="None" 
        Skin="Sitefinity" OnInsertCommand="grdArbeitsprofile_InsertCommand">
        <MasterTableView AutoGenerateColumns="False" EditMode="EditForms" CommandItemDisplay="Top" DataKeyNames="ID">
         <Columns>
          <telerik:GridBoundColumn
            DataField="Bezeichnung"
            HeaderText="Bezeichnung"
            SortExpression="Bezeichnung"
            UniqueName="Bezeichnung" />
          <telerik:GridBoundColumn
            DataField="Bemerkung"
            HeaderText="Bemerkung"
            SortExpression="Bemerkung"
            UniqueName="Bemerkung" />
         </Columns>
             <EditFormSettings EditFormType="AutoGenerated"  InsertCaption="Neues Arbeitsprofil" CaptionFormatString="Arbeitsprofil: {0}" CaptionDataField="Bezeichnung">                   
</EditFormSettings>
        </MasterTableView>
        <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">
            <Selecting AllowRowSelect="True" />
 </ClientSettings>
     </telerik:RadGrid>   
    </asp:Content>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Pepperhost.Greifplaner.Web.Data;
using Telerik.Web.Design;
using Telerik.Web.UI;
  
  
namespace Web.Stammdaten
{
    using DTO=Pepperhost.Greifplaner.Web.Data.DataTransferobjects;
    public partial class Arbeitsprofile : System.Web.UI.Page
    {
        DataProvider db = new DataProvider();
  
        protected void Page_Load(object sender, EventArgs e)
        {
            grdArbeitsprofile.UpdateCommand+= new GridCommandEventHandler(grdArbeitsprofile_UpdateCommand);
           // grdArbeitsprofile.InsertCommand+= new GridCommandEventHandler(grdArbeitsprofile_InsertCommand);
            grdArbeitsprofile.NeedDataSource+=new GridNeedDataSourceEventHandler(grdArbeitsprofile_NeedDataSource);
              
            grdArbeitsprofile.DataSource = db.GetArbeitsprofilListe();
            grdArbeitsprofile.DataBind();
  
        }
  
        protected void grdArbeitsprofile_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.PerformInsertCommandName)
            {
                 GridEditableItem item = e.Item as GridEditableItem;  
          
                try
                {
                    DTO.Arbeitsprofil arbeitsprofil = new DTO.Arbeitsprofil();
  
                   arbeitsprofil.Bemerkung = (item["Bemerkung"].Controls[0] as TextBox).Text;
                   arbeitsprofil.Bezeichnung = (item["Bezeichnung"].Controls[0] as TextBox).Text;
                   db.CreateArbeitsprofil(arbeitsprofil);
                }
                catch (Exception ex)
                {
                    grdArbeitsprofile.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));
                    e.Canceled = true;
                }
  
            }
             
        }
  
        protected void grdArbeitsprofile_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
  
            try
            {
                grdArbeitsprofile.DataSource = db.GetArbeitsprofilListe();
                grdArbeitsprofile.DataBind();
            }
            catch (Exception ex)
            {
                grdArbeitsprofile.MasterTableView.NoRecordsTemplate = new NoRecordsTemplate(ex.Message);
            }
            finally
            {
                  
            }
  
        }
        protected void grdArbeitsprofile_UpdateCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {  
           GridEditableItem item = e.Item as GridEditableItem;
  
           try
           {
               DTO.Arbeitsprofil arbeitsprofil = new DTO.Arbeitsprofil();
               arbeitsprofil.ID=(int)item.OwnerTableView.DataKeyValues[item.ItemIndex]["ID"];
               arbeitsprofil.Bemerkung = (item["Bemerkung"].Controls[0] as TextBox).Text;
               arbeitsprofil.Bezeichnung = (item["Bezeichnung"].Controls[0] as TextBox).Text;
               db.UpdateArbeitsprofil(arbeitsprofil);
           }
           catch (Exception ex)
           {
               grdArbeitsprofile.Controls.Add(new LiteralControl("Unable to update Employee. Reason: " + ex.Message));
               e.Canceled = true;
           }
        }
       }
    class NoRecordsTemplate : ITemplate
    {
        private string _Message;
        public NoRecordsTemplate(string Message)
        {
            _Message = Message;
        }
  
        public void InstantiateIn(Control container)
        {
            Label lbl = new Label();
            lbl.ID = "Label1";
            lbl.Text = _Message;
            lbl.ForeColor = System.Drawing.Color.RoyalBlue;
            container.Controls.Add(lbl);
        }
    }
  
}

2 Answers, 1 is accepted

Sort by
0
Falk
Top achievements
Rank 1
answered on 12 Aug 2010, 01:29 PM
No Ideas ?
0
Daniel
Telerik team
answered on 17 Aug 2010, 03:12 PM
Hello Falk,

Please mind the following:
1) You should never call Rebind/DataBind in the NeedDataSource handler
2) You should never call DataBind when using advanced data-binding.
3) You don't have to call DataBind on each postback when using simple data-binding

I recommend that you examine the following links:
Simple Data-binding
Advanced Data-binding

Let me know if the problem still persists.

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Falk
Top achievements
Rank 1
Answers by
Falk
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or