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

Radgrid does not open Edit and Insert Mode

1 Answer 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alper Cem
Top achievements
Rank 1
Alper Cem asked on 06 Dec 2013, 01:08 PM
Hi, I have an issue with radgrid. I have LÄ°stview and radgrid inside listview. I can not run edit mode and Add new record in radgrid. I followed this example  http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/form-template-update/defaultcs.aspx.

If i add this insert and edit is opening by default but when i press add new record it does not open.

protected void gridCustomerLocationPhone_PreRender(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                gridCustomerLocationPhoneEdit.MasterTableView.IsItemInserted = true;
                gridCustomerLocationPhoneEdit.Rebind();
            }
        }

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ActivityManagement.Main;
using CT.Base;
using BIL.Base.Exceptions;
using Telerik.Web.UI;
using BIL.Base.FormManagement;
using CT.Base.ModelView;
using BIL.Base.ModelView;
using BIL.Common.Utilities;
 
namespace ActivityManagement.Common.Pages
{
    public partial class ManageCustomerDetail : CTBasePage
    {
        #region Page Private Members
 
        private Customer selectedCustomer;
        private CustomerLocation selectedCustomerLocation;
        private Label lblIdEdit;
        private Label lblIdDelete;
        private RadComboBox comboCountryEdit;
        private RadComboBox comboCityEdit;
        private TextBox txtNameEdit;
        private TextBox txtAddressEdit;
        private RadComboBox comboCountryInsert;
        private RadComboBox comboCityInsert;
        private TextBox txtNameInsert;
        private TextBox txtAddressInsert;
        private RadGrid gridCustomerLocationPhoneEdit;
 
        #endregion
 
        #region Page Public Members
 
        public Customer SelectedCustomer
        {
            get
            {
                if (selectedCustomer == null)
                {
                    selectedCustomer = (Customer)webApplicationManager.Session["SelectedCustomer"];
 
                    if (selectedCustomer == null)
                        throw new SessionVariableNotFoundException("SelectedCustomer", activityApplicationManager.Context.SystemName);
                }
 
                return selectedCustomer;
            }
            set
            {
                selectedCustomer = value;
                Session["SelectedCustomer"] = selectedCustomer;
            }
        }
 
        public CustomerLocation SelectedCustomerLocation
        {
            get
            {
                if (selectedCustomerLocation == null)
                {
                    selectedCustomerLocation = (CustomerLocation)webApplicationManager.Session["SelectedCustomerLocation"];
 
                    if (selectedCustomerLocation == null)
                        throw new SessionVariableNotFoundException("SelectedCustomerLocation", activityApplicationManager.Context.SystemName);
                }
 
                return selectedCustomerLocation;
            }
            set
            {
                selectedCustomerLocation = value;
                Session["SelectedCustomerLocation"] = selectedCustomerLocation;
            }
        }
 
        #endregion
 
        #region Page Events
 
        protected void Page_Load(object sender, EventArgs e)
        {
            PageMessageLabel = lblMessage;
            InitializePageContext();
            if (!Page.IsPostBack)
            {
                InitializePage();
                listViewCustomerDetail.Skin = "Metro";
                listViewCustomerDetail.Rebind();
            }
        }
 
        #endregion
 
        #region Toolbar
 
 
        #endregion
 
        #region ButtonOperations
 
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            listViewCustomerDetail.Rebind();
        }
 
        protected void btnInitInsert_Click(object sender, System.EventArgs e)
        {
            listViewCustomerDetail.ShowInsertItem();
            listViewCustomerDetail.FindControl("btnInitInsert").Visible = false;
        }
 
        #endregion
 
        #region ComboOperations
 
        protected void comboCountries_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            var comboBox = ((RadComboBox)sender);
            Dictionary<string, string> customerCitiesDictionary = ctBaseManager.CityOperations.GetCityListAsDictionaryByCountryId(Convert.ToInt32(comboBox.SelectedValue));
            webApplicationManager.UI.LoadComboBox(comboCityEdit, customerCitiesDictionary, false, "");
        }
 
        protected void comboCountries_DataBinding(object sender, EventArgs e)
        {
            var comboBox = ((RadComboBox)sender);
            Dictionary<string, string> customerCountriesDictionary = ctBaseManager.CountryOperations.GetCountryListAsDictionary();
            webApplicationManager.UI.LoadComboBox(comboBox, customerCountriesDictionary, false, "");
            Dictionary<string, string> customerCitiesDictionary = ctBaseManager.CityOperations.GetCityListAsDictionaryByCountryId(Convert.ToInt32(comboBox.SelectedValue));
            webApplicationManager.UI.LoadComboBox(comboCityEdit, customerCitiesDictionary, false, "");
        }
 
        protected void comboCountriesInsert_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            var comboBox = ((RadComboBox)sender);
            Dictionary<string, string> customerCitiesDictionary = ctBaseManager.CityOperations.GetCityListAsDictionaryByCountryId(Convert.ToInt32(comboBox.SelectedValue));
            webApplicationManager.UI.LoadComboBox(comboCityInsert, customerCitiesDictionary, false, "");
        }
 
        protected void comboCountriesInsert_DataBinding(object sender, EventArgs e)
        {
            var comboBox = ((RadComboBox)sender);
            Dictionary<string, string> customerCountriesDictionary = ctBaseManager.CountryOperations.GetCountryListAsDictionary();
            webApplicationManager.UI.LoadComboBox(comboBox, customerCountriesDictionary, false, "");
            Dictionary<string, string> customerCitiesDictionary = ctBaseManager.CityOperations.GetCityListAsDictionaryByCountryId(Convert.ToInt32(comboBox.SelectedValue));
            webApplicationManager.UI.LoadComboBox(comboCityInsert, customerCitiesDictionary, false, "");
        }
 
 
        protected void comboPhoneType_DataBinding(object sender, EventArgs e)
        {
            var comboBox = ((RadComboBox)sender);
            Dictionary<string, string> phoneTypeDictionary = ctBaseManager.CustomerPhoneOperations.GetPhoneTypeListAsDictionary();
            webApplicationManager.UI.LoadComboBox(comboBox, phoneTypeDictionary, false, "");
        }
 
        #endregion
 
        #region ListViewCustomerDetail
 
        protected void listViewCustomerDetail_NeedDataSource(object sender, RadListViewNeedDataSourceEventArgs e)
        {
            if (!listViewCustomerDetail.DataSourceIsAssigned)
            {
                BindData();
            }
        }
 
        private void BindData()
        {
            IList<CustomerLocationView> customerLocationList;
            bool? isActive = TypeConversionWorker.ConvertStringValueToNullableBoolean(comboIsActive.SelectedValue);
            bool? isDeleted = TypeConversionWorker.ConvertStringValueToNullableBoolean(comboIsDeleted.SelectedValue);
            customerLocationList = ctBaseManager.CustomerLocationOperations.GetCustomerLocationViewByCustomerId(this.SelectedCustomer.Id, isActive, isDeleted);
            listViewCustomerDetail.DataSource = customerLocationList;
        }
 
        private void BindPhoneData()
        {
 
        }
 
        protected void listViewCustomerDetail_ItemDataBound(object sender, RadListViewItemEventArgs e)
        {
            if (e.Item is RadListViewDataItem)
            {
                RadListViewDataItem item = e.Item as RadListViewDataItem;
 
                RadGrid radgrid = (RadGrid)e.Item.FindControl("gridCustomerLocationPhone");
                gridCustomerLocationPhoneEdit = radgrid;
                ajaxManager.AjaxSettings.AddAjaxSetting(radgrid, radgrid, ajaxLoadPanel);
                Label lblId = (Label)e.Item.FindControl("lblId");
                IList<CustomerLocationPhoneView> customerLocationPhoneList = ctBaseManager.CustomerPhoneOperations.GetCustomerLocationPhoneByParameter(Convert.ToInt32(lblId.Text));
                radgrid.DataSource = customerLocationPhoneList;
                radgrid.Rebind();
                //Label subject = (Label)e.Item.FindControl("lblSubject");
                //subject.Text = webApplicationManager.Framework.GetGlobalizationKeyValue("Subject") + " : ";
 
                //string messageSubject = (string)DataBinder.Eval(item.DataItem, "MessageSubject");
                //int lineCountSubject = messageSubject.Split('\n').Length;
                //TextBox textMessageSubject = (TextBox)e.Item.FindControl("txtMessageSubject");
                //textMessageSubject.Rows = lineCountSubject;
                //textMessageSubject.Text = messageSubject;
 
                //string message = (string)DataBinder.Eval(item.DataItem, "Message");
                //int lineCount = message.Split('\n').Length + 2;
                //TextBox textMessage = (TextBox)e.Item.FindControl("lblMessage");
                //textMessage.Rows = lineCount;
 
                //if (!webApplicationManager.Framework.Globalization.IsCultureInfoDefaultSystemCulture())
                //{
                //    Label from = (Label)e.Item.FindControl("lblFrom");
                //    from.Text = webApplicationManager.Framework.GetGlobalizationKeyValue("From");
                //    Label to = (Label)e.Item.FindControl("lblTo");
                //    to.Text = webApplicationManager.Framework.GetGlobalizationKeyValue("To");
                //}
            }
        }
 
        protected void listViewCustomerDetail_ItemCommand(object sender, RadListViewCommandEventArgs e)
        {
            if ((e.CommandName == RadListView.PerformInsertCommandName))
            {
                this.SelectedCustomerLocation = new CustomerLocation();
                CreateSelectedCustomerLocation(this.SelectedCustomerLocation);
                listViewCustomerDetail.InsertItemPosition = RadListViewInsertItemPosition.None;
                listViewCustomerDetail.FindControl("btnInitInsert").Visible = true;
            }
            if ((e.CommandName == RadListView.UpdateCommandName))
            {
                this.SelectedCustomerLocation = ctBaseManager.CustomerLocationOperations.GetObjectById(cl => cl.Id == Convert.ToInt32(lblIdEdit.Text));
                ChangeSelectedCustomerLocation(this.SelectedCustomerLocation, "Edit");
                listViewCustomerDetail.InsertItemPosition = RadListViewInsertItemPosition.None;
                listViewCustomerDetail.FindControl("btnInitInsert").Visible = true;
            }
            if ((e.CommandName == RadListView.DeleteCommandName))
            {
                this.SelectedCustomerLocation = ctBaseManager.CustomerLocationOperations.GetObjectById(cl => cl.Id == Convert.ToInt32(lblIdEdit.Text));
                ChangeSelectedCustomerLocation(this.SelectedCustomerLocation, "Delete");
                listViewCustomerDetail.InsertItemPosition = RadListViewInsertItemPosition.None;
                listViewCustomerDetail.FindControl("btnInitInsert").Visible = true;
                listViewCustomerDetail.EditIndexes.Clear();
            }
            if ((e.CommandName == RadListView.CancelCommandName))
            {
                listViewCustomerDetail.InsertItemPosition = RadListViewInsertItemPosition.None;
                listViewCustomerDetail.FindControl("btnInitInsert").Visible = true;
            }
        }
 
        protected void listViewCustomerDetail_ItemCreated(object sender, RadListViewItemEventArgs e)
        {
            if (e.Item.ItemType == RadListViewItemType.EditItem)
            {
                lblIdEdit = e.Item.FindControl("lblId") as Label;
                comboCityEdit = e.Item.FindControl("comboCountries") as RadComboBox;
                comboCityEdit = e.Item.FindControl("comboCities") as RadComboBox;
                txtNameEdit = e.Item.FindControl("txtName") as TextBox;
                txtAddressEdit = e.Item.FindControl("txtAddress") as TextBox;
            }
            if (e.Item.ItemType == RadListViewItemType.InsertItem)
            {
                lblIdEdit = e.Item.FindControl("lblId") as Label;
                comboCityInsert = e.Item.FindControl("comboCountries") as RadComboBox;
                comboCityInsert = e.Item.FindControl("comboCities") as RadComboBox;
                txtNameInsert = e.Item.FindControl("txtName") as TextBox;
                txtAddressInsert = e.Item.FindControl("txtAddress") as TextBox;
            }
            if (e.Item.ItemType == RadListViewItemType.DataItem)
            {
                RadGrid radgrid = (RadGrid)e.Item.FindControl("gridCustomerLocationPhone");
                gridCustomerLocationPhoneEdit = radgrid;
            }
        }
 
        #endregion
 
        #region GridCustomerLocationPhone
 
        protected void gridCustomerLocationPhone_ItemCreated(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && (e.Item.IsInEditMode))
            {
                GridEditableItem editableItem = (GridEditableItem)e.Item;
                //SetupInputManager(editableItem);
            }
        }
 
 
        protected void gridCustomerLocationPhone_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
        }
 
        protected void gridCustomerLocationPhone_UpdateCommand(object source, GridCommandEventArgs e)
        {
        }
 
        protected void gridCustomerLocationPhone_InsertCommand(object source, GridCommandEventArgs e)
        {
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
        }
 
        protected void gridCustomerLocationPhone_DeleteCommand(object source, GridCommandEventArgs e)
        {
        }
 
        protected void gridCustomerLocationPhone_ItemCommand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
            {
                GridEditCommandColumn editColumn = (GridEditCommandColumn)gridCustomerLocationPhoneEdit.MasterTableView.GetColumn("EditCommandColumn");
                editColumn.Visible = false;
                e.Item.OwnerTableView.InsertItem();
            }
            else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
            {
                e.Canceled = true;
            }
            else
            {
                GridEditCommandColumn editColumn = (GridEditCommandColumn)gridCustomerLocationPhoneEdit.MasterTableView.GetColumn("EditCommandColumn");
                if (!editColumn.Visible)
                    editColumn.Visible = true;
            }
 
            if (e.CommandName == RadGrid.PerformInsertCommandName)
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
            }
            gridCustomerLocationPhoneEdit.Rebind();
        }
 
        protected void gridCustomerLocationPhone_PreRender(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                gridCustomerLocationPhoneEdit.Rebind();
            }
        }
 
        #endregion
 
        #region Methods
 
        private void InitializePageContext()
        {
            try
            {
                //Ajax
                ajaxManager.AjaxSettings.AddAjaxSetting(ManageActivityMessagesToolBar.InstanceToolbar, lblMessage, ajaxLoadPanel);
                ajaxManager.AjaxSettings.AddAjaxSetting(ManageActivityMessagesToolBar.InstanceToolbar, listViewCustomerDetail, ajaxLoadPanel);
                ajaxManager.AjaxSettings.AddAjaxSetting(listViewCustomerDetail, listViewCustomerDetail, ajaxLoadPanel);
 
                //Toolbar
                SetToolbar(ManageActivityMessagesToolBar);
            }
            catch (Exception exception)
            {
                lblMessage.Text = webApplicationManager.Framework.PublishException(exception, webApplicationManager.Framework.ApplicationContext.CurrentUser);
            }
        }
 
        private void InitializePage()
        {
            WebFormDialog webFormDialog = webApplicationManager.UI.FindDialogOwner(Page.Request.Path);
            if (webFormDialog != null)
            {
                webApplicationManager.UI.RefreshDialogsList(webFormDialog);
            }
 
            txtCustomerName.Text = this.SelectedCustomer.Name;
            //Globalization
            //Form Object Properties
            if (webApplicationManager.Framework.Form.Context.IsCustomFormParametersActive)
            {
                //IList<SystemFormParameterView> list = webApplicationManager.Framework.Form.FormParameterOperations.GetSystemFormParametersByTypeName("ManageCustomerDetail");
                //listViewCustomerDetail.PageSize = webApplicationManager.Framework.Form.SetFormParameterValue<int>(list, listViewCustomerDetail.PageSize, "listViewCustomerDetail", "PageSize"); ;
                //listViewCustomerDetail.AllowPaging = webApplicationManager.Framework.Form.SetFormParameterValue<bool>(list, listViewCustomerDetail.AllowPaging, "listViewCustomerDetail", "AllowPaging");
            }
        }
 
        private void ChangeSelectedCustomerLocation(CustomerLocation selectedCustomerLocation, string changeType)
        {
            if (changeType.Equals("Edit"))
            {
                selectedCustomerLocation.Name = txtNameEdit.Text;
                selectedCustomerLocation.Adress = txtAddressEdit.Text;
                selectedCustomerLocation.CityId = Convert.ToInt32(comboCityEdit.SelectedValue);
            }
            else if (changeType.Equals("Delete"))
            {
                selectedCustomerLocation.IsDeleted = true;
            }
            selectedCustomerLocation.ChangeDate = webApplicationManager.Framework.GetCurrentDateTime();
            selectedCustomerLocation.ChangedBy = webApplicationManager.Framework.ApplicationContext.CurrentUser.Name;
            ctBaseManager.SaveCustomerLocation(selectedCustomerLocation);
        }
 
        private void CreateSelectedCustomerLocation(CustomerLocation selectedCustomerLocation)
        {
            selectedCustomerLocation.CustomerId = this.SelectedCustomer.Id;
            selectedCustomerLocation.Name = txtNameInsert.Text;
            selectedCustomerLocation.Adress = txtAddressInsert.Text;
            selectedCustomerLocation.CityId = Convert.ToInt32(comboCityInsert.SelectedValue);
            selectedCustomerLocation.IsActive = true;
            selectedCustomerLocation.IsDeleted = false;
            selectedCustomerLocation.InsertDate = webApplicationManager.Framework.GetCurrentDateTime();
            selectedCustomerLocation.InsertedBy = webApplicationManager.Framework.ApplicationContext.CurrentUser.Name;
            ctBaseManager.SaveCustomerLocation(selectedCustomerLocation);
        }
 
        #endregion
    }
}
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeBehind="ManageCustomerDetail.aspx.cs" Inherits="ActivityManagement.Common.Pages.ManageCustomerDetail" %>
 
<%@ Register Src="~/Framework/UserControls/BILToolbar.ascx" TagName="BILToolbar"
    TagPrefix="Toolbar" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
    <div id="FormContainer" style="width: 700px; min-width: 700px;">
        <div id="FormTitle">
            <asp:Label ID="lblFormTitle" runat="server" CssClass="StandartFormTitle" Text="Müşteri Ä°letiÅŸim Detay"></asp:Label>
        </div>
        <div id="FormToolbar">
            <Toolbar:BILToolbar ID="ManageActivityMessagesToolBar" runat="server" />
        </div>
        <div id="FormMessage">
            <asp:Label ID="lblMessage" runat="server" CssClass="StandartMessageLabel"></asp:Label>
        </div>
        <div id="FormGroupElements">
            <div id="ParameterGroupActSubject" class="FormElement">
                <asp:Label ID="lblCustomerName" runat="server" Text="Müşteri" CssClass="StandartFormLabel"
                    Width="100px"></asp:Label>
                <asp:TextBox ID="txtCustomerName" runat="server" Width="170px" Enabled="False" BackColor="#F3F3F3"
                    Font-Bold="True" ForeColor="Red"></asp:TextBox>
            </div>
            <div id="ParameterGroupActiveDeleted" class="FormElement">
                <asp:Label ID="lblIsActive" runat="server" Text="Aktif mi?" CssClass="StandartFormLabel"
                    Width="100px"></asp:Label>
                <telerik:RadComboBox ID="comboIsActive" runat="server" Width="150px">
                </telerik:RadComboBox>
                <asp:Label ID="lblIsDeleted" runat="server" Text="SilinmiÅŸ mi?" CssClass="StandartFormLabel"
                    Width="100px"></asp:Label>
                <telerik:RadComboBox ID="comboIsDeleted" runat="server" Width="150px">
                </telerik:RadComboBox>
                <telerik:RadButton ID="btnSearch" runat="server" Text="Sorgula" OnClick="btnSearch_Click"
                    CausesValidation="True" Style="height: 20px; left: 10px;" Width="90px">
                    <Icon PrimaryIconUrl="~/Images/Buttons/Search16X16_0.png" />
                </telerik:RadButton>
            </div>
            <div id="ListViewCustomerDetail" class="FormElement">
                <asp:Panel ID="ListViewPanel1" runat="server" CssClass="ListViewPanel">
                    <telerik:RadListView ID="listViewCustomerDetail" runat="server" ItemPlaceholderID="CustomersDetailContainer"
                        DataKeyNames="Id" AllowPaging="true" OnItemCommand="listViewCustomerDetail_ItemCommand"
                        OnNeedDataSource="listViewCustomerDetail_NeedDataSource" OnItemDataBound="listViewCustomerDetail_ItemDataBound"
                        OnItemCreated="listViewCustomerDetail_ItemCreated">
                        <LayoutTemplate>
                            <fieldset id="FiledSet1" style="max-width: 100%;" class="RadListView RadListView_<%#Container.Skin %>">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr>
                                        <td>
                                            <telerik:RadDataPager ID="RadDataPager1" runat="server" PagedControlID="listViewCustomerDetail"
                                                PageSize="1">
                                                <Fields>
                                                    <telerik:RadDataPagerButtonField FieldType="FirstPrev"></telerik:RadDataPagerButtonField>
                                                    <telerik:RadDataPagerButtonField FieldType="Numeric" PageButtonCount="6"></telerik:RadDataPagerButtonField>
                                                    <telerik:RadDataPagerButtonField FieldType="NextLast"></telerik:RadDataPagerButtonField>
                                                    <%--<telerik:RadDataPagerPageSizeField PageSizeComboWidth="60" PageSizeText="Kayıt Sayısı: ">
                                                    </telerik:RadDataPagerPageSizeField>--%>
                                                    <telerik:RadDataPagerGoToPageField CurrentPageText="Sayfa: " TotalPageText="of" SubmitButtonText="Git"
                                                        TextBoxWidth="40"></telerik:RadDataPagerGoToPageField>
                                                    <%--<telerik:RadDataPagerTemplatePageField>
                                                            <PagerTemplate>
                                                                <div style="float: right; padding-left: 50px;">
                                                                    <b>Items
                                                                        <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# (Container.Owner.TotalRowCount > 0)? Container.Owner.StartRowIndex + 1  : 0%>"></asp:Label>
                                                                        to
                                                                        <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# (Container.Owner.TotalRowCount > 0)? Container.Owner.StartRowIndex + Container.Owner.PageSize : 0 %>"></asp:Label>
                                                                        of
                                                                        <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.Owner.TotalRowCount%>"></asp:Label>
                                                                        <br />
                                                                    </b>
                                                                </div>
                                                            </PagerTemplate>
                                                        </telerik:RadDataPagerTemplatePageField>--%>
                                                </Fields>
                                            </telerik:RadDataPager>
                                        </td>
                                    </tr>
                                </table>
                                <asp:PlaceHolder ID="CustomersDetailContainer" runat="server"></asp:PlaceHolder>
                                <div style="clear: both">
                                </div>
                                <table style="width: 100%; margin-top: 5px;">
                                    <tr>
                                        <td style="text-align: right">
                                            <asp:Button ID="btnInitInsert" runat="server" Text="Yeni" Width="100px" OnClick="btnInitInsert_Click">
                                            </asp:Button>
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <fieldset>
                                <table width="100%" cellpadding="0" cellspacing="5">
                                    <tr>
                                        <td>
                                            <table width="100%" cellpadding="0" cellspacing="5">
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Label ID="lblId" runat="server" Text='<%# Eval("Id") %>' Visible="false"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblName" runat="server" Text="Adı:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:Label ID="lblName1" runat="server" Text='<%# Eval("Name") %>' Width="100%"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblAddress" runat="server" Text="Address:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:Label ID="lblAddress1" runat="server" Text='<%# Eval("Address") %>' Width="100%"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblCity" runat="server" Text="Åžehir:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:Label ID="lblCity1" runat="server" Text='<%# Eval("City") %>' Width="100%"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblCountry" runat="server" Text="Ãœlke:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:Label ID="lblCountry1" runat="server" Text='<%# Eval("Country") %>' Width="100%"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblIsActive" runat="server" Text="Aktif mi?" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:CheckBox ID="chkIsActive" runat="server" Enabled="false" Checked='<%# Eval("IsActive") %>' />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblIsDeleted" runat="server" Text="SilinmiÅŸ mi?" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:CheckBox ID="chkIsDeleted" runat="server" Enabled="false" Checked='<%# Eval("IsDeleted") %>' />
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <table style="width: 95%; margin-top: 10px">
                                                <tr>
                                                    <td>
                                                        <asp:Button ID="btnEdit" runat="server" Text="Düzenle" CommandName="Edit" Width="70px">
                                                        </asp:Button>
                                                    </td>
                                                </tr>
                                            </table>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <asp:Label ID="lblLocationPhone" runat="server" Text="Telefonlar" Width="100px" Style="margin-top: 10px"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <telerik:RadGrid runat="server" ID="gridCustomerLocationPhone" AutoGenerateColumns="false"
                                                AllowPaging="true" Width="100%" OnUpdateCommand="gridCustomerLocationPhone_UpdateCommand"
                                                OnItemCreated="gridCustomerLocationPhone_ItemCreated" OnDeleteCommand="gridCustomerLocationPhone_DeleteCommand"
                                                OnInsertCommand="gridCustomerLocationPhone_InsertCommand" OnItemCommand="gridCustomerLocationPhone_ItemCommand"
                                                OnPreRender="gridCustomerLocationPhone_PreRender">
                                                <MasterTableView CommandItemDisplay="Top"  DataKeyNames="Id">
                                                    <Columns>
                                                        <telerik:GridEditCommandColumn ButtonType="ImageButton" />
                                                        <telerik:GridBoundColumn DataField="Id" UniqueName="Id" HeaderText="No" Display="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="CustomerLocationId" UniqueName="CustomerLocationId"
                                                            HeaderText="No" Display="false">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="PhoneType" UniqueName="PhoneType" HeaderText="Telefon Tipi">
                                                        </telerik:GridBoundColumn>
                                                        <telerik:GridBoundColumn DataField="Phone" UniqueName="Phone" HeaderText="Telefon" />
                                                        <telerik:GridBoundColumn DataField="InternalPhone" UniqueName="InternalPhone" HeaderText="Dahili" />
                                                        <telerik:GridBoundColumn DataField="Pbx" UniqueName="Pbx" HeaderText="Pbx" />
                                                        <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                                                            ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" />
                                                    </Columns>
                                                    <EditFormSettings EditFormType="Template">
                                                        <FormTemplate>
                                                            <table width="100%" cellpadding="0" cellspacing="5">
                                                                <tr>
                                                                    <td>
                                                                        <table width="100%" cellpadding="0" cellspacing="5">
                                                                            <tr>
                                                                                <td>
                                                                                    <asp:Label ID="lblPhoneType" runat="server" Text="Telefon Tipi:" Width="100px"></asp:Label>
                                                                                </td>
                                                                                <td>
                                                                                    <telerik:RadComboBox ID="comboPhoneType" runat="server" Width="200px" OnDataBinding="comboPhoneType_DataBinding">
                                                                                    </telerik:RadComboBox>
                                                                                </td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td>
                                                                                    <asp:Label ID="lblPhone" runat="server" Text="Telefon:" Width="100px"></asp:Label>
                                                                                </td>
                                                                                <td>
                                                                                    <telerik:RadMaskedTextBox ID="txtPhone" runat="server" Width="160px" Mask="#### (###) ### ## ##" Text='<%#Bind("Phone")%>'  />
                                                                                </td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td>
                                                                                    <asp:Label ID="lblInternal" runat="server" Text="Dahili:" Width="100px"></asp:Label>
                                                                                </td>
                                                                                <td>
                                                                                    <telerik:RadNumericTextBox ID="txtInternal" runat="server" Width="40px" DataType="System.Int32"
                                                                                        MaxLength="4" MaxValue="9999" MinValue="0" Text='<%#Bind("InternalPhone")%>'>
                                                                                        <NumberFormat ZeroPattern="n" DecimalDigits="0" GroupSeparator=""></NumberFormat>
                                                                                    </telerik:RadNumericTextBox>
                                                                                </td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td>
                                                                                    <asp:Label ID="lblPbx" runat="server" Text="Pbx" Width="100px"></asp:Label>
                                                                                </td>
                                                                                <td>
                                                                                    <telerik:RadNumericTextBox ID="txtPbx" runat="server" Width="40px" DataType="System.Int32"
                                                                                        MaxLength="4" MaxValue="9999" MinValue="0" Text='<%#Bind("Pbx")%>'>
                                                                                        <NumberFormat ZeroPattern="n" DecimalDigits="0" GroupSeparator=""></NumberFormat>
                                                                                    </telerik:RadNumericTextBox>
                                                                                </td>
                                                                            </tr>
                                                                        </table>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                                                        </asp:Button>
                                                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
                                                                            CommandName="Cancel"></asp:Button>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </FormTemplate>
                                                    </EditFormSettings>
                                                </MasterTableView>
                                                <PagerStyle Mode="NextPrevAndNumeric" />
                                            </telerik:RadGrid>
                                        </td>
                                    </tr>
                                </table>
                            </fieldset>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <fieldset class="fieldset">
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td>
                                            <table cellpadding="0" cellspacing="5">
                                                <tr>
                                                    <td colspan="2">
                                                        <asp:Label ID="lblId" runat="server" Text='<%#Bind("Id")%>' Visible="false" Width="100px"></asp:Label>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblName" runat="server" Text="Adı:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtName" runat="server" Text='<%#Bind("Name")%>' Width="200px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblAddress" runat="server" Text="Address:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtAddress" runat="server" Text='<%#Bind("Address")%>' Width="200px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblCountry" runat="server" Text="Ãœlke:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadComboBox ID="comboCountries" runat="server" AutoPostBack="True" Width="200px"
                                                            OnSelectedIndexChanged="comboCountries_SelectedIndexChanged" OnDataBinding="comboCountries_DataBinding">
                                                        </telerik:RadComboBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblCity" runat="server" Text="Åžehir:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadComboBox ID="comboCities" runat="server" Width="200px">
                                                        </telerik:RadComboBox>
                                                    </td>
                                                </tr>
                                            </table>
                                            <tr>
                                                <td>
                                                    <table style="width: 95%; margin-top: 20px">
                                                        <tr>
                                                            <td>
                                                                <asp:Button ID="btnUpdate" runat="server" Text="Güncelle" CommandName="Update" Width="70px">
                                                                </asp:Button>
                                                            </td>
                                                            <td style="text-align: center">
                                                                <asp:Button ID="btnDelete" runat="server" Text="Sil" CommandName="Delete" Width="70px">
                                                                </asp:Button>
                                                            </td>
                                                            <td style="text-align: right">
                                                                <asp:Button ID="btnCancel" runat="server" Text="Vazgeç" CommandName="Cancel" Width="70px">
                                                                </asp:Button>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                </table>
                            </fieldset>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <fieldset class="fieldset">
                                <table cellpadding="0" cellspacing="0">
                                    <tr>
                                        <td>
                                            <table cellpadding="0" cellspacing="5">
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblName" runat="server" Text="Adı:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtName" runat="server" Text='<%#Bind("Name")%>' Width="200px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblAddress" runat="server" Text="Address:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:TextBox ID="txtAddress" runat="server" Text='<%#Bind("Address")%>' Width="200px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblCountry" runat="server" Text="Ãœlke:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadComboBox ID="comboCountries" runat="server" AutoPostBack="True" Width="200px"
                                                            OnSelectedIndexChanged="comboCountriesInsert_SelectedIndexChanged" OnDataBinding="comboCountriesInsert_DataBinding">
                                                        </telerik:RadComboBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td>
                                                        <asp:Label ID="lblCity" runat="server" Text="Åžehir:" Width="100px"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <telerik:RadComboBox ID="comboCities" runat="server" Width="200px">
                                                        </telerik:RadComboBox>
                                                    </td>
                                                </tr>
                                            </table>
                                            <tr>
                                                <td>
                                                    <table style="width: 95%; margin-top: 20px">
                                                        <tr>
                                                            <td>
                                                                <asp:Button ID="btnPerformInsert" runat="server" Text="Ekle" CommandName="PerformInsert"
                                                                    Width="70px"></asp:Button>
                                                            </td>
                                                            <td style="text-align: center">
                                                                <asp:Button ID="btnCancel" runat="server" Text="Vazgeç" CommandName="Cancel" Width="70px">
                                                                </asp:Button>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>
                                            </tr>
                                </table>
                            </fieldset>
                        </InsertItemTemplate>
                        <EmptyDataTemplate>
                            <fieldset style="width: 800px">
                            </fieldset>
                        </EmptyDataTemplate>
                    </telerik:RadListView>
                </asp:Panel>
                <div style="clear: both">
                </div>
            </div>
        </div>
    </div>
</asp:Content>

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 11 Dec 2013, 01:18 PM
Hi Alper,

In the provided code there is RadGrid defined in the markup and in the code-behind you are creating different RadGrid object which should not be done.

Also the data source for the grid should not be set in the ItemDataBound handler for the RadListView control. The recommended approach is to set RadGrid's DataSource property only in NeedDataSource as it is called automatically. If you need to rebind RadGrid the Rebind() method should be called. If you would like additional information on using NeedDataSource event it is available in this topic.

Additionally when adding Ajax settings programmatically a page lifecycle event should be used as suggested in this article. This needs to be done to ensure that the settings will be added properly when the page is loaded.


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
Alper Cem
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or