Changing the EditForm .ascx based on what grid called it

3 posts, 1 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 07 Nov 2013 Link to this post

    So I have an address popup and I want to display some different wording or hide some textboxes based on what radGrid has called it.  Whats the best way to do this?
    <MasterTableView EditMode="PopUp" CommandItemDisplay="Top"  DataKeyNames="AddressId">
     
                       <EditFormSettings  UserControlName="~/AddressEdit.ascx" EditFormType="WebUserControl" InsertCaption="Add new Address" PopUpSettings-Width="800px"
            FormStyle-BackColor="AliceBlue" FormStyle-BorderWidth="5px" FormStyle-BorderColor="Turquoise" CaptionFormatString="Edit Address ID: {0}"
            CaptionDataField="AddressId">
                 <EditColumn UniqueName="EditCommandColumnAddr"/>
        </EditFormSettings>
  2. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1793 posts

    Posted 12 Nov 2013 Link to this post

    Hi Dan,

    One possible approach for such requirement is to handle the Page_Load event of the user control and get reference to the RadGrid that is currently opening the user control:
    protected void Page_Load(object sender, EventArgs e)
    {
        string gridID = (NamingContainer as GridEditFormItem).OwnerGridID;
    }

    Once you have the ID of the grid you could add custom logic for different grids:
    protected void Page_Load(object sender, EventArgs e)
    {
        string gridID = (NamingContainer as GridEditFormItem).OwnerGridID;
        if (gridID == "RadGrid1")
        {
            TextBox1.Visible = false;
            Label1.Text = "Grid1 edit form";
        }
        else
        {
            Label1.Text = "Grid2 edit form";
        }
    }

    I have prepared a sample page for your convenience. Please refer to the attached files and see if this helps with your requirements.

     

    Regards,
    Konstantin Dikov
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 12 Nov 2013 Link to this post

    Thanks, that works great.
Back to Top