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

ASP.NET customValidator accessing items from template column of combobox

3 Answers 56 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JD.
Top achievements
Rank 1
JD. asked on 28 Sep 2011, 09:27 PM

Hi,

I have a Client Side CustomValidator Control, Is there a way to access selected item's CityCode value from comboxbox's itemtemplate. using client side javascript
--JD
( Please advice, some easy workable workaround )

<telerik:RadComboBox ID="RadComboBox2" Runat="server" TabIndex="3"
                      DropDownWidth="320px"
                       HighlightTemplatedItems="true"
                         DataSourceID="EDSStateList" DataTextField="StateName"
                        DataValueField="StateCode" SelectedValue='<%# Bind("FK_StateCode") %>'>
                         <HeaderTemplate>
                          <ul>
                             <li class="col1">StateName</li>
                             <li class="col2">CityName</li>
                             <li class="col3">CityCode</li>
                         </ul>
                         </HeaderTemplate>
  
                         <ItemTemplate>
                             <ul>
                                 <li class="col1">
                                     <%# DataBinder.Eval(Container.DataItem, "StateName")%></li>
                                 <li class="col2">
                                     <%# DataBinder.Eval(Container.DataItem, "CityName")%></li>
                                 <li class="col3">
                                     <%# DataBinder.Eval(Container.DataItem, "CityCode") %></li>
                             </ul>
                         </ItemTemplate>
  
                         <FooterTemplate>
             
                        </FooterTemplate>
  
                    </telerik:RadComboBox>

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 29 Sep 2011, 12:05 PM
Hi,

You could use get_selectedItem function of the RadComboBox's JavaScript object to get the selected item. And then use findControl of the method to find child controls of RadComboBoxItem object.
Check these resources for more information:
http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcombobox.html
http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcomboboxitem.html
http://www.telerik.com/help/aspnet-ajax/combobox-templates-accessing-controls.html

Regards,
Vasil
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
0
JD.
Top achievements
Rank 1
answered on 29 Sep 2011, 01:16 PM
HI

Below line give error.

   function APICodeValidate(sender, args) {
  
// Function APICodeValidate is a CustomValidator Control, attached to a Textbox which is
// inside FormTemplate of a RadGrid Control 
which should check RadComboBox2's Selected Row value,
// RadComboBox2 is a MultiColumn also inside FormTemplate.  
// The Value to access and compare is 3rd Column of a MultiColumn Template
// based on seleted combox row.
               var combo = $find("<%= RadComboBox2.ClientID %>");
               var i = 0;
           }

Because RadComboBox2 is within Grid Control's FormTemplate available during Insert or Edit.
0
Vasil
Telerik team
answered on 29 Sep 2011, 02:22 PM
Hello,

Check these help topic about accessing cells inside the grid's rows:
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html
http://www.telerik.com/help/aspnet-ajax/grid-griddataitem-findcontrol.html

A bit more easier would be to if you have only one combo on your page (when you have only one insert or form) that you want to access. You could remember it in one variable during it's load and then use it later when you need. This approach will work even if the combo is inside an grid.

<script type="text/javascript">   
var MyComboBox = null;
 
function ComboBoxClientLoad(sender, object)
{
  MyComboBox = sender;
}
</script>
 
 ........
 ........
 ........
 
<telerik:RadComboBox runat="server" OnClientLoad="ComboBoxClientLoad">

Kind regards,
Vasil
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
JD.
Top achievements
Rank 1
Answers by
Vasil
Telerik team
JD.
Top achievements
Rank 1
Share this question
or