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

[Solved] Demo Request for in-line edit using a custom user control

4 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 20 May 2009, 03:01 AM
I'm sure this is a duplicate request, but I can't find what I'm looking for.  I'm hoping someone can point me in the right direction.

I need a demo/forum post with an example of a dynamic user control.  Based upon the type of record being edited, I want the control to render itself differently for each type.  (Most of my work is in the code behind as well, so demos with stuff in the mark up doesn't fit too well.)

For example,

I have a data grid, lets say a grid of a automobiles.  Each automobile record has an automobile-type-indicator (T=truck, C=Convertable, W=Wagon, S=Sedan, ....).

When the user drills down on a truck recod .. I pass the indicator "T" to the user control.  I have this wired up and working in the Item Created Event.

        protected void grdDefinition_ItemCreated(object sender, GridItemEventArgs e)  
        {  
 
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)  
            {  
                 
                AutomobilSelector userControl = (AutomobilSelector )e.Item.FindControl(GridEditFormItem.EditFormUserControlID);  
 
                userControl.AutoTypeId = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["auto_type_id"].ToString(), CultureInfo.InvariantCulture);  
            }  
]  
             


The user control then says, "hey I'm a truck" so it renders the truck panel which shows a prompt for the size of the truck bed, towing package, etc.

When the user clicks a Convertable record, the user control says, "hey, I'm a convertable" so it now hides the truck stuff and shows a panel with a drop down for rag top or hard top, transmission type, etc.

I can do some of this, but the user control's page life cycle is different when I put it into an inline edit vs. just putting it on a standard page.  Stuff like setting a label value within page load doesn't render, instead I have to hook a data binding event in order to do stuff in the code behind..

My lastest challenge is when, say I'm showing the convertable panel.  The user says, "lets make it a truck instead" and changes the autoType drop down from convertable to truck.  I then execute a onSelectedValueChange event, to show/hide text boxes concerning truck options.  However, none of the new panels render.


        protected void ddlAutoType_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)  
        {  
            pnlTruck.Visible = false;  
            pnlConvertable.Visible = false;  
            pnlSedan.Visible = false;  
            switch (ddlAutoType.SelectedValue.ToString(CultureInfo.InvariantCulture))  
            {  
                case "T":  
                    pnlTruck.Visible = true;  
                    break;  
                case "S":  
                    pnlSedan.Visible = true;  
                    break;  
                case "C":  
                    pnlConvertable.Visible = true;  
                    break;  
    
                default:  
                    break;  
            }  
        }  
 
I can hit this code when the drop down changes, but I can't seem to do anything to effect the rendering of the control.

so if anyone has any examples to help guide me, I'd love to see them. ... thank you very much.

4 Answers, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 1
answered on 22 May 2009, 03:13 PM
I think I worked through my life cycle issues. 

For those interested, it appears that the grid rebuilt the user control all the time.  So for the one issue where I wanted a drop down on the user control with a onSelected event, I found that any data on the control was dropped and recreated.

I had to shove everything into session, and even make my a user control post back indicator. 

Anyway it looks pretty good.
0
Rosen
Telerik team
answered on 25 May 2009, 07:19 AM
Hi Tim,

I have attached a very simple implementation of the described functionality. Please take a look and let us know if this helps or maybe I'm missing something obvious.

Greetings,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jeff
Top achievements
Rank 1
answered on 27 May 2009, 07:32 PM
Thanks. 
The example is a bit too simple.  When I added dynamic text boxes and panels things got a bit harder.  A lot of life cycle stuff.

The first time rendering I'd pull the existing user description from a database and shove it on a text box.  I found that page_load would execute but not render the results into the text box.  I had to move txtDescription.Text = DataAccess.GetDescription(); into the preRender.

Then the user changes the description in that text box ...

then the user changes the drop down list .. the selected index change event is hit .. the page reloads ... and wait i've lost what the user put in that text box .. and since !postback doesn't work (lifecycle issue) I replace it with the value in the database...

I got past all of this, so i'm good.  However for those wondering, I had to hook the selected index change event, save the text box value into session, along with my own session value for postback.  when the user control renders i ask my session values if i should load it from  the database or use what was capture in session.


0
Rosen
Telerik team
answered on 30 May 2009, 06:14 AM
Hello Tim,

I'm glad that you have managed to solve the issues you were facing. Please let us know if we can assist you with anything else concerning this matter.

Greetings,
Rosen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Jeff
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Rosen
Telerik team
Share this question
or