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

How do i find control in ItemTemplate on RadCombobox?

8 Answers 1099 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Waranya
Top achievements
Rank 1
Waranya asked on 08 Feb 2008, 02:51 AM
I use RadCombobox version "Prometheus" I want to get value from control but I can't find control in ItemTemplate.
Help me please!!!
PuM

8 Answers, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 08 Feb 2008, 01:41 PM
Hello Waranya,

Please find below a sample code snippet that shows the needed approach.

ASPX:
<form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Text=" " AllowCustomText="true" Width="300px">  
        <Items> 
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" /> 
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" /> 
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem3" /> 
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem4" /> 
        </Items> 
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
        <ExpandAnimation Type="OutQuart" /> 
        <ItemTemplate> 
            <asp:TextBox ID="TextBox1" runat="server" Width="280px"></asp:TextBox> 
        </ItemTemplate> 
    </telerik:RadComboBox> 
</form> 

Code-behind:
protected void Page_Load(object sender, EventArgs e)  
    {  
        foreach(RadComboBoxItem myItem in RadComboBox1.Items)  
        {  
            TextBox myBox = (TextBox)myItem.FindControl("TextBox1");  
            myBox.Text = "This is" + " " + myItem.Text;  
        }  
    } 


Kind regards,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Waranya
Top achievements
Rank 1
answered on 09 Feb 2008, 12:53 AM
Thank you for answer. Sorry I not told you that I want to find control in client side, but this answer i will use next time.
Help me angain...
pum
0
Paul
Telerik team
answered on 11 Feb 2008, 11:22 AM
Hi Waranya,

Please find below a sample code snippet that shows the needed approach on the client.

<form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
 
    <script type="text/javascript">  
    function GetValue()  
    {  
        var myTBox = $get('<%= ((TextBox)RadComboBox1.FindItemByText("RadComboBoxItem3").FindControl("TextBox1")).ClientID %>');  
        alert(myTBox.value);  
    }  
    </script> 
 
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Text=" " AllowCustomText="true" Width="300px">  
        <Items> 
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" /> 
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" /> 
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem3" /> 
            <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem4" /> 
        </Items> 
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
        <ExpandAnimation Type="OutQuart" /> 
        <ItemTemplate> 
            <asp:TextBox ID="TextBox1" runat="server" Width="280px"></asp:TextBox> 
        </ItemTemplate> 
    </telerik:RadComboBox> 
    <input id="Button1" type="button" value="button" onclick="GetValue()" /> 
</form> 

Kind regards,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Waranya
Top achievements
Rank 1
answered on 12 Feb 2008, 02:49 AM

I use code below but error "Object reference not set to an instance of an object."
help me!!!
pum

function

OnClientSelectedIndexChanged(sender, eventArgs)

{

var myTBox = $get('<%= ((HiddenField)cboEditVersion.FindControl("hEdit")).ClientID %>');

alert(myTBox.value);

}

</

script>

<

telerik:RadComboBox ID="cboEditVersion" runat="server" Skin="Outlook" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"

Width="200px" MarkFirstMatch="true" EnableLoadOnDemand="true"

HighlightTemplatedItems="true" ItemRequestTimeout="500" OnItemDataBound="cboEditVersion_ItemDataBound" >

<HeaderTemplate>

<table style="width: 100%; text-align: left">

<tr>

<td style="width: 60px;">Date</td>

<td style="width: 120px;">User</td>

<td style="width: 0px;"></td>

</tr>

</table>

</HeaderTemplate>

<ItemTemplate>

<table style="width: 100%; text-align: left">

<tr>

<td style="width: 60px;"><%# DataBinder.Eval(Container.DataItem, "Date") %></td>

<td style="width: 120px;"><%# DataBinder.Eval(Container.DataItem, "User") %></td>

<td style="width: 0px;"><asp:HiddenField ID="hEdit" Value='<%# DataBinder.Eval(Container.DataItem, "Version") %>' runat="server" /></td>

</tr>

</table>

</ItemTemplate>

<CollapseAnimation Duration="200" Type="OutQuint" />

<ExpandAnimation Type="OutQuart" />

</telerik:RadComboBox>

0
Paul
Telerik team
answered on 12 Feb 2008, 01:08 PM
Hi Waranya,

Here's your modified JS function that works as expected.

<script type="text/javascript">          
function OnClientSelectedIndexChanged(sender, eventArgs)  
{  
    var myTBox = $get('<%= ((HiddenField)cboEditVersion.SelectedItem.FindControl("hEdit")).ClientID %>');  
    alert(myTBox.value);  
}  
</script> 


Kind regards,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Waranya
Top achievements
Rank 1
answered on 13 Feb 2008, 01:53 AM
I modify JS already but It's not work. (Show error "Object reference not set to an instance of an object.")
I don't know reason error but my RadCombobox live in user control .
0
Paul
Telerik team
answered on 13 Feb 2008, 02:24 PM
Hello Waranya,

I believe that the best way to proceed would be if you open a new support ticket and send us a sample project where the problem can be reproduced and we will check it right away.

Kind regards,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Waranya
Top achievements
Rank 1
answered on 15 Feb 2008, 04:12 AM
I sent my problem to support ticket already..
pum
Tags
ComboBox
Asked by
Waranya
Top achievements
Rank 1
Answers by
Paul
Telerik team
Waranya
Top achievements
Rank 1
Share this question
or