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

Get Edit form Controls from outside RadGrid

4 Answers 514 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mahmoud
Top achievements
Rank 1
Mahmoud asked on 26 Jan 2012, 01:31 PM
Hi,

I have two related comboboxes here in Edit Form Template . and OnSelectedIndexChanged Loads the Items in the second ComboBox.

This Code works Fine on Insert Mode but on Edit Mode it Can't see the ComboBoxes ( return Nothing ):

Protected Sub CustomerName_SelectedIndexChanged(ByVal o As Object, ByVal e As RadComboBoxSelectedIndexChangedEventArgs)
 
 
        Dim editedItem As GridEditFormItem = DirectCast(rgOpportunities.MasterTableView.GetItems(GridItemType.EditFormItem)(0), GridEditFormItem)
        
        Dim CustomerCombo As RadComboBox = DirectCast(editedItem.FindControl("rcbCustomerName"), RadComboBox)
        Dim ContactsCombo As RadComboBox = DirectCast(editedItem.FindControl("rcbContactName"), RadComboBox)
 
        If (CustomerCombo.DataSourceID IsNot Nothing) Then
            CustomerCombo.DataSourceID = String.Empty
        End If
        ContactsCombo.DataSource = LoadContacts(e.Value)
        'ContactsCombo.Items.Clear()
        ContactsCombo.OpenDropDownOnLoad() = True
        ContactsCombo.DataBind()
        If ContactsCombo.Items.Count > 0 Then
            Session("ContactID") = ContactsCombo.Items(0).Value
        Else
            Session("ContactID") = ""
        End If
 
 
    End Sub


--- > CustomerCombo and ContactsCombo Access the edit form and gets the RadComboBoxes and Works Fine in InsertMode
But in Edit Mode , Iam not able to Access The editform and get controls by this way or any other way !

Can anyone helps me in this Please ( Urgent ).

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 27 Jan 2012, 06:36 AM
Hello Mahmoud,

Try the following code.
C#:
protected void grid_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
    GridEditableItem item = (GridEditableItem)e.Item;
    RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
 }
}

Thanks,
Princy.
0
Mahmoud
Top achievements
Rank 1
answered on 28 Jan 2012, 02:48 PM
Hello Princy,

I'm Sorry , That's not What I Want .

The thing is : I want to do this from SelectedIndexChanged Event Handler or from PreRender Event

because the event fired after opening edit mode . .. it means Just rhose two events will fire..

Please Help me in this..,

Regarding,
Mahmoud 
0
Accepted
Shinu
Top achievements
Rank 2
answered on 30 Jan 2012, 06:08 AM
Hello Mahmoud,

You can access the edit form by using the Naming container property of the RadComboBox. Here is the sample code.
C#:
void list_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
   {
       RadComboBox rdcbx=(RadComboBox)o;
       GridEditableItem editedItem =rdcbx.NamingContainer as GridEditableItem;
      //Code goes here
   }

Thanks,
Shinu.
0
Mahmoud
Top achievements
Rank 1
answered on 02 Feb 2012, 12:23 PM
Thanks, Shinu

it works as expected...

Regarding,
Mahmoud
Tags
Grid
Asked by
Mahmoud
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mahmoud
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or