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

Pass Variables to Edit ASCX

6 Answers 219 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 09 Jul 2008, 08:11 PM
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!

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Jul 2008, 05:39 AM
Hi Mike,

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


Shinu.
0
Vlad
Telerik team
answered on 10 Jul 2008, 06:19 AM
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
0
Mike
Top achievements
Rank 1
answered on 10 Jul 2008, 01:32 PM
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?

0
Richard Thurgood
Top achievements
Rank 1
answered on 16 Sep 2008, 06:01 PM
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

}


 

0
Perry
Top achievements
Rank 1
answered on 18 Nov 2015, 01:58 PM

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

0
Eyup
Telerik team
answered on 23 Nov 2015, 09:44 AM
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
Tags
Grid
Asked by
Mike
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Vlad
Telerik team
Mike
Top achievements
Rank 1
Richard Thurgood
Top achievements
Rank 1
Perry
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or