Pass Variables to Edit ASCX

7 posts, 0 answers
  1. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 09 Jul 2008 Link to this post

    I have the following code.

      <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderStyle-Width="50" EditImageUrl="~/images/edit.gif" /> 
     
    more....grid.......code  
     
    <EditFormSettings UserControlName="~/controls/Edit.ascx" EditFormType="WebUserControl">  
        <EditColumn UniqueName="EditCommandColumn1">  
        </EditColumn> 
    </EditFormSettings> 

    How do I pass the parameters in the grid like the column name, id, and date to the ascx page?

    Thanks!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 10 Jul 2008 Link to this post

    Hi Mike,

    Go through the following online demo discussing about the UserControl edit form and see whether it helps.
    User control edit form


    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 10 Jul 2008 Link to this post

    Hello Mike,

    If you have this in your UserControl:

            private object _dataItem = null;
            public object DataItem
            {
                get
                {
                    return this._dataItem;
                }
                set
                {
                    this._dataItem = value;
                }
            }

    the grid populate automatically DataItem property on edit.


    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Mike
    Mike avatar
    338 posts
    Member since:
    Jun 2008

    Posted 10 Jul 2008 Link to this post

    Shinu,

    That is the example I am using as a refernce, thank you for responding.  But it does not show me how the dropdownlist in the user control passes the variable from the grid to the user control dropdownlist and selects the courtesy i.e. "Dr.", "Mrs.", etc.

    Even with the Example below it does not show  a REAL world way of binding the form data from codebehind with DataTables.  I do not use magic code from drop and drag tools.  

    Example

    I really need your assistance on this please show me what event is fired when clicking on the "Edit" link and once it's clicked how does it query the data to fill in the from!


    Vlad,
    Do I put this in the code behind of the user control "ascx.cs"?  If so how do I access them if I want username, state, and last name from the grid?

  6. Richard Thurgood
    Richard Thurgood avatar
    26 posts
    Member since:
    Nov 2007

    Posted 16 Sep 2008 Link to this post

    You know, I create my forms as Web User Controls and the way I pass values is by "binding" a hidden field to the key value I want. So for example, at the bottom of my control ascx page, I include something like:

    <

    asp:Label ID="MyID" Text='<%# Eval("myID")%>' runat="server" Visible="false"></asp:Label>

    Now, I don't use "Page_Load" because that value won't be populated at that time. Instead, I use OnPreRender() and call a method called LoadPage() which then populates the page's data etc..  Something like this (please note that I'm using custom entities - this is only to give you an idea):

    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;

    public partial class MyFormControl : ControlBase
    {

        #region Members
        private bool _isLoaded = false;
        #endregion

        #region Properties
        /// <summary>
        /// Use MyID for primary key
        /// </summary>
        public string UniqueKey
        {
            get
            {
                return MyID.Text;
            }
            set
            {
                MyID.Text = value;
            }
        }

        /// <summary>
        /// Set when control is loaded
        /// </summary>
        private bool IsLoaded
        {
            get
            {
                return _isLoaded;
            }
            set
            {
                _isLoaded = value;
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Method used to load page data.
        /// </summary>
        private void LoadPage()
        {
            PopulateDropdownList();
            Populate();
        }

        /// <summary>
        /// Populates List data
        /// </summary>
        private void PopulateDropdownList()
        {
            if (MyDropdownList.Items.Count < 1)
            {
                MyDropdownList.DataTextField = MyEntity.DBFieldName.Description.ToString();
                MyDropdownList.DataValueField = MyEntity.DBFieldName.IDValue.ToString();
                MyDropdownList.DataSource = MyEntity.GetList();
                MyDropdownList.DataBind();

                MyDropdownList.Items.Insert(0, new RadComboBoxItem("Select One...", String.Empty));
            }
        }

        /// <summary>
        /// Populates page data
        /// </summary>
        private void Populate()
        {
            Populate(this.UniqueKey);
        }

        private void Populate(string myID)
        {
            //get saved data
            MyEntity entity = new MyEntity();
            if (!String.IsNullOrEmpty(myID))
            {
                entity = MyEntity.GetByID(myID);
            }

            PopulateUIFromEntity(entity, this);
        }

        /// <summary>
        /// Saves page data
        /// </summary>
        /// <returns>True if successful</returns>
        public bool Save()
        {
            IsLoaded = true;
            bool success = false;

            MyEntity entity = new MyEntity();
            if (!String.IsNullOrEmpty(this.UniqueKey))
            {
                entity = MyEntity.GetByID(this.UniqueKey);
            }

            //update with form data
            entity = (MyEntity)PopulateEntityFromUI(entity, this);

            success = entity.SaveData();
            if (success)
            {
                //update the unique key field
                this.UniqueKey = entity.MyID;
            }

            return success;
        }

        /// <summary>
        /// Deletes current page data
        /// </summary>
        /// <returns>True if successful</returns>
        public bool Delete()
        {
            IsLoaded = true;
            bool success = false;

            //TODO: Add code here

            return success;

        }
        #endregion

        #region AJAX Events

        #endregion

        #region Form Events
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            this.Save();
        }

        protected override void OnPreRender(EventArgs e)
        {
            if (!IsLoaded)
            {
                //load page data
                LoadPage();
            }

            base.OnPreRender(e);
        }
        #endregion

    }


     

  7. Perry
    Perry avatar
    25 posts
    Member since:
    Jul 2015

    Posted 18 Nov 2015 in reply to Mike Link to this post

    Hey Mike,

     

    Sorry I am very late to the party but I was wondering if you ever got an answer to this question. I am having the same problem passing a parameter to the control page

     

    Thank

    Perry

  8. Eyup
    Admin
    Eyup avatar
    3015 posts

    Posted 23 Nov 2015 Link to this post

    Hi Perry,

    I've already replied to your query in the following post. I suggest that we continue our conversation in the mentioned thread:
    http://www.telerik.com/forums/need-help-with-radgrid-edititemtemplate

    Regards,
    Eyup
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017