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

RadGrid Edit Form interim postbacks before final update

4 Answers 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DMG
Top achievements
Rank 1
DMG asked on 15 Apr 2010, 08:23 PM
I have a grid with a template form for editing. I initially load my controls on the item data bound event but would like to also postback and update a series of dropdowns before the final insert or update.  My problem is that when I postback from the RadComboBox I can not seem to get access to the container to update the other dropdown. If I, as an option, create a custom command and use ItemCommand I am unable to see the GridDataItem.IsInEditMode as true nor cast to a GridEditFormItem to access these other fields.  BTW if the command is one of the core CRUD commands like update or insert I have no problem with accessing these fields.

Ideally I'd like to just autopost the dropdowns to update but I can live with a button if I can get that to work. 

Hope all that makes sense. Any ideas? Thanks.

Sample code
aspx:

 

 
<EditFormSettings EditFormType="Template" >   
 <FormTemplate>   
 <asp:Panel ID="Panel1" runat="server" DefaultButton="btnUpdate">   
 ...  
   <asp:Button ID="btnTest" Text="Test" runat="server" CausesValidation="False" CommandName="InterimUpdate"></asp:Button>   
 
 </asp:Panel>   
 
</FormTemplate>   
 
</EditFormSettings>   
 
  

 

 

protected void rg_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)   
{  
    if (e.CommandName == "InterimUpdate")        <== simple embeded command button see above   
 
    {  
          if (e.Item is GridEditFormItem && e.Item.IsInEditMode)            <== Never gets past this on custom command    
           {   
 
                string s = ((RadComboBox)e.Item.FindControl("rcb1")).SelectedValue; 
                RadComboBox rcb = new RadComboBox();
                rcb = e.Item.FindControl("rcb2"as RadComboBox;   
                rcb.DataTextField = "Name";   
                rcb.DataValueField = "ID";   
                rcb.DataSource = getAllXXX(s);   
 
                rcb.DataBind();  
            }  
 
    }  
 

 

 

 

 

 

 



Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 16 Apr 2010, 06:59 AM
Hello,

You can access the container by using NamingContainer property of control (RadComboBox that initiate the postback) in SelectedIndexChanged event as shown below.

C#:
 
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        RadComboBox rcb1 = (RadComboBox)o; 
        GridEditFormItem edititem = (GridEditFormItem)rcb1.NamingContainer; 
        string s = rcb1.SelectedValue; 
        RadComboBox rcb = (RadComboBox)edititem.FindControl("rcb2"); 
        rcb.DataTextField = "Name"
        rcb.DataValueField = "ID"
        rcb.DataSource = getAllXXX(s); 
        rcb.DataBind(); 
    } 

Regards,
Shinu.
0
DMG
Top achievements
Rank 1
answered on 16 Apr 2010, 04:52 PM
Thanks Shinu works great .

Regards,
Dave
0
Rohan
Top achievements
Rank 1
answered on 20 Dec 2012, 12:14 PM

Hi Shinu,

 

 I have one user control with rad grid and rad window . The rad Grid is generated dynamically on page load of user control in is postback. This is user control work in all my conditions and defined functionally …… My problem is – whenever i add this user control to to rad grid edit user control –then my user control (rad grid) columns are not created because of postback of radgrid edit …..

Please provide and way of solution to work out …….

0
Eyup
Telerik team
answered on 24 Dec 2012, 02:41 PM
Hello Rohan,

In your scenario, the (!IsPostBack) condition prevents the configuration of your grid. Therefore, I suggest you to use the PageInit approach:
http://www.telerik.com/help/aspnet-ajax/grid-programmatic-creation.html

It works as expected on my end. Please give it a try and let me know about the result.

Kind regards,
Eyup
the Telerik team
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 their blog feed now.
Tags
Grid
Asked by
DMG
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
DMG
Top achievements
Rank 1
Rohan
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or