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

Control in item template is not recognizing

1 Answer 92 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Regeesh Joseph
Top achievements
Rank 1
Regeesh Joseph asked on 26 Mar 2012, 12:24 PM
Hai,

I have a hiddenfield in the item template of a Radcombo. I have to take the value of hiddenfield in the SelectedIndexChanged event of radcombo. I used the following method as per your website refernece for radcombo. This code was working fine. But one day it started not working, showing null reference exception in finding the hiddenfield. I didn't change anything.

protected

 

void rcbTruck_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)

 


{

RadComboBox

 

combo = (RadComboBox)sender;

 

 

RadComboBoxItem item = (RadComboBoxItem)combo.SelectedItem;

 


hidDailyOrderDetailId2.Value = ((

HiddenField)item.FindControl("hidDailyOrderDetailId1")).Value;

 


}

aspx

<

 

asp:HiddenField ID="hidDailyOrderDetailId2" runat="server" />

 



<

 

telerik:RadComboBox ID="rcbTruck" runat="server" DropDownWidth="250px" Width="250px"

 

 

ShowToggleImage="true" Height="140px" AllowCustomText="True" MarkFirstMatch="False"

 

 

HighlightTemplatedItems="True" TabIndex="2" EmptyMessage="--Select--" AutoPostBack="true"

 

 

EnableLoadOnDemand="True" Skin="Web20" ToolTip="Please Select truck" MaxHeight="250px"

 

 

OnItemsRequested="rcbTruck_ItemsRequested" OnSelectedIndexChanged="rcbTruck_SelectedIndexChanged">

 

 

<ItemTemplate>

 

 

<input id="hidScheduledStartTime" type="hidden" runat="server" value='<%#DataBinder.Eval(Container.DataItem,"ScheduledTime") %>' />

 

 

<asp:Label ID="lblVehicleName" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"VehicleName") %>'></asp:Label>

 

 

<asp:HiddenField ID="hidDailyOrderDetailId1" runat="server" Value='<%#DataBinder.Eval(Container.DataItem,"Daily_Order_Detail_Id") %>' />

 

 

</ItemTemplate>

 

 

</telerik:RadComboBox>

 

1 Answer, 1 is accepted

Sort by
0
Ivana
Telerik team
answered on 29 Mar 2012, 11:27 AM
Hi Regeesh,

This would be a valid approach to access the elements within the Item template if RadComboBox does not have the load on demand feature enabled. For more information on this matter you could refer to the following help article: [http://www.telerik.com/help/aspnet-ajax/combobox-load-on-demand-access-items-server-side.html].

To copy some value from one hidden field to another, when the selected index of RadComboBox is changed is something that can be easily implemented on the client. Here is an example:
function OnClientSelectedIndexChanged(sender, args) {
    $get("HiddenField2").value = $get("HiddenField1").value;
}

At the following link you can find more about the client API of RadComoBox: [http://www.telerik.com/help/aspnet-ajax/combobox-client-side-basics.html].

Kind regards,
Ivana
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
ComboBox
Asked by
Regeesh Joseph
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Share this question
or