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

Find Control in code behind

4 Answers 332 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Saravanan
Top achievements
Rank 1
Saravanan asked on 11 Mar 2010, 11:11 AM
I have a radCombobox inside the itemTemplate of RadGrid. I want to bind the radcombobox in the CodeBehind . so I tried using the following Code

Protected

 

Sub RadGrid1_EditCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.EditCommand

 

If e.Item.ItemType = GridItemType.AlternatingItem Or e.Item.ItemType = GridItemType.Item Then  

 

Dim item As Telerik.Web.UI.GridDataItem

item = e.Item

 

Dim radCombo As RadComboBox

radCombo = item(

"DropdownColumn").FindControl("radCombo")

 

 

 

radCombo.DataSource = objDetailDal.GetAccSAPDetails(objDetailInfo).Tables(0)

radCombo.DataBind()

End If  

 

End Sub 

 

telerik:GridTemplateColumn HeaderText="Sap material Item " UniqueName="DropdownColumn" >

 

<ItemTemplate>

 

<asp:Label ID="lblItemNo" Width="150px" runat="server" CssClass="label" Text='<%# DataBinder.Eval (Container.DataItem, "ITEM") %>'></asp:Label  

 

 

</ItemTemplate>

 

<EditItemTemplate>

 

 

<telerik:RadComboBox ID="radCombo" runat ="server" />
</EditItemTemplate>

 

 

 

 

 

 

</telerik:GridTemplateColumn>
But the Find Control method returns null values.

Kindly help me

 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 11 Mar 2010, 12:00 PM

Hello Raghuraman,

You can bind the RadComboBox in ItemDataBopound event of grid as shown below.

C#:

 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)   
{   
    if ((e.Item is GridEditFormItem) && (e.Item.IsInEditMode))   
    {   
        GridEditFormItem insertItem = (GridEditFormItem)e.Item;   
        RadComboBox combo = (RadComboBox)insertItem.FindControl("ddlPeatBU");   
        // Now bind the combo  
        combo.DataSourceID = "SqlDataSource1";   
        combo.DataTextField = "CustomerID";   
        combo.DataValueField = "CustomerID";   
        combo.DataBind();     
    }    
}  

-Shinu.

0
Saravanan
Top achievements
Rank 1
answered on 11 Mar 2010, 01:05 PM

Thanks Shinu.

I tried your set of code but of no use.
i have used AllowAutomaticUpdates="True" property.
So when i click 'edit' it goes to Radgrid1_Itemdatabound event but the condition
If (TypeOf e.Item Is GridEditFormItem) AndAlso (e.Item.IsInEditMode) Then

is always false

Please help me.

0
Veli
Telerik team
answered on 11 Mar 2010, 06:07 PM
Hello Raghuraman,

Try with this check instead:

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
{  
    if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))  
    {  
        GridEditFormItem insertItem = (GridEditableItem)e.Item;  
        RadComboBox combo = (RadComboBox)insertItem.FindControl("ddlPeatBU");  
        // Now bind the combo 
        combo.DataSourceID = "SqlDataSource1";  
        combo.DataTextField = "CustomerID";  
        combo.DataValueField = "CustomerID";  
        combo.DataBind();    
    }   
}



All the best,
Veli
the Telerik team

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 Public Issue Tracking system and vote to affect the priority of the items.
0
Saravanan
Top achievements
Rank 1
answered on 12 Mar 2010, 10:17 AM
Thanks team . Its working now .
Tags
General Discussions
Asked by
Saravanan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Saravanan
Top achievements
Rank 1
Veli
Telerik team
Share this question
or