ComboBox SelectedIndexChanged

4 posts, 0 answers
  1. JSON
    JSON avatar
    78 posts
    Member since:
    Mar 2010

    Posted 15 Jul 2010 Link to this post

    Hello,

    I have a combobox in a GridTemplateColumn that is configured for LoadOnDemand. I need to subscribe to a OnSelectedIndexChanged event in Edit Mode to populate other controls when a value is selected but the event signature does not recoginize the RadComboBoxSelectedIndexChangedEventArgs delegate I reference in the OnSelectedIndexChanged method.

    I cannot determine what the issue is.

    Thank you,

    Steve O.


    Code Behind
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------

    using

     

    System;

     

     

     

     

     

    using System.Collections;

     

     

     

     

     

    using System.Configuration;

     

     

     

     

     

    using System.Data;

     

     

     

     

     

    using System.Linq;

     

     

     

     

     

    using System.Web;

     

     

     

     

     

    using System.Web.Security;

     

     

     

     

     

    using System.Web.UI;

     

     

     

     

     

    using System.Web.UI.WebControls;

     

     

     

     

     

    using System.Web.UI.WebControls.WebParts;

     

     

     

     

     

    using System.Web.UI.HtmlControls;

     

     

     

     

     

    using System.Xml.Linq;

     

     

     

     

     

    using Telerik;

     

     

     

     

     

    using

     

    Telerik.Web.UI;

     

     


    using
    System.Collections.Generic;

     

     

     

     

     

    using SubSonic;
     

     

     

     

    using System.Web.Services;

     

     

    using System.Data.SqlClient;

     

     

     

     

     

    namespace CIMT.Forms

     

     

     

    {

     

     

    private void Roster_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)

     

    {

     

     

    GridEditableItem editedItem = (sender as DropDownList).NamingContainer as GridEditableItem;

     

     

    int id = Convert.ToInt32((editedItem["ResourceId"].Controls[0] as DropDownList).SelectedValue);

     

     

    StoredProcedure sp = new StoredProcedure("Get_Resource_Details");

     

    sp.Command.AddParameter(

    "@id", @id, DbType.Int32);

     

     

     

    sp.Command.AddOutputParameter(

    "@position");

     

     

     

    sp.Command.AddOutputParameter(

    "@agency");

     

     

     

    sp.Execute();

    position.Text =

    Convert.ToString(sp.OutputValues[0]).Trim();

     

     

     

    agency.Text =

    Convert.ToString(sp.OutputValues[1]);

     

     

     

    }
    }

    ASPX
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------

    <DetailTables>

     

     

     

    <telerik:GridTableView runat="server"

     

     

    DataKeyNames="RosterId"

     

     

     

    Name="Rosters"


    GridLines
    ="Both"

     

     

     

    Width="100%"


    DataSourceID
    ="SqlDataSource4"

     

     

     

    BorderStyle="Solid"

     

     

    BorderWidth="1px"

     

     

    BorderColor="Blue"

     

     

    CommandItemDisplay="Top"

     

     

    ExpandCollapseColumn-CollapseImageUrl="~/Images/zoom-out-icon[1].png"

     

     

    ExpandCollapseColumn-ExpandImageUrl="~/Images/zoom-in-icon[1].png" >

     

     

     

    <ParentTableRelation>

     

     

     

    <telerik:GridRelationFields MasterKeyField="UnitLogId" DetailKeyField="UnitLogId" />

     

     

     

    </ParentTableRelation>

     

     

     

    <ExpandCollapseColumn ExpandImageUrl="~/Images/zoom-in-icon[1].png" CollapseImageUrl="~/Images/zoom-out-icon[1].png"></ExpandCollapseColumn>

     

     

     

    <EditFormSettings>

     

     

     

    <EditColumn UniqueName="EditCommandColumn" ButtonType="ImageButton"

     

     

    CancelImageUrl="~/Images/filterCancel.png"

     

     

     

    UpdateImageUrl="~/Images/selecttag.png"

     

     

    InsertImageUrl="~/Images/selecttag.png"

     

     

    EditImageUrl="~/Images/edit-icon[1].png">

     

     

     

    </EditColumn>

     

     

     

    </EditFormSettings>

     

     

     

    <Columns>

     

     

     

    <telerik:GridTemplateColumn DataField="ResourceId"

     

     

    UniqueName="ResourceId"

     

     

    HeaderText="Resource">

     

     

     

    <ItemTemplate>

     

     

     

    <%

     

     

     

    # GetName(Convert.ToString(Eval("ResourceId")))%>

     

     

    </ItemTemplate>

     

     

     

    <HeaderStyle Font-Bold="True"></HeaderStyle>

     

     

     

    <ItemStyle Wrap="false" />

     

     

     

    <EditItemTemplate>

     

     

     

     

    <telerik:RadComboBox ID="rcbUnitLeader" 
     

     

    runat="server"

     

     

     

     

    AutoPostBack="true" 
     

     

    HighlightTemplatedItems="true"

     

     

    DropDownWidth="350px"

     

     

    EnableLoadOnDemand="true"

     

     

    EnableVirtualScrolling="true"

     

     

     

    ShowMoreResultsBox="true"

     

     

    OnSelectedIndexChanged="Roster_SelectedIndexChanged"

     

     

     

    EmptyMessage="Select Roster Resource"

     

     

     

    OnItemsRequested="RosterResource_ItemsRequested"

     

     

     

    Height="200px">

     

     

     

    <HeaderTemplate>

     

     

     

    <table style="width: 250px; text-align: left;">

     

     

     

    <tr>

     

     

     

    <td style="width: 200px;">Name</td>

     

     

     

    <td style="width: 50px;">Agency</td>

     

     

     

    </tr>

     

     

     

    </table>

     

     

     

    </HeaderTemplate>

     

     

     

    <ItemTemplate>

     

     

     

    <table style="width: 250px; text-align: left; white-space:nowrap">

     

     

     

    <tr>

     

     

     

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

     

     

     

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

     

     

     

    </tr>

     

     

     

    </table>

     

     

     

    </ItemTemplate>

     

     

     

    </telerik:RadComboBox>

     

     

     

    </EditItemTemplate>

     

     

     

    </telerik:GridTemplateColumn>

     

     

     

     

  2. Helen
    Admin
    Helen avatar
    1052 posts

    Posted 19 Jul 2010 Link to this post

    Hello,

    We are not exactly sure what might be causing the issue. Please find attached a project which is working at our side.

    Does it work at your side?

    Regards,
    Helen
    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
  3. Noel
    Noel avatar
    11 posts
    Member since:
    Sep 2006

    Posted 18 Jul 2013 Link to this post

    protected void cmbStoresIssueStockCode_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
            {
                #region Retrieves the selected item
                RadComboBox cmbStoresIssueStockCode = sender as RadComboBox;
                if (cmbStoresIssueStockCode.SelectedIndex > -1)
                {
     
                    RadComboBoxItem stockItem = cmbStoresIssueStockCode.SelectedItem;
                    GridDataItem item = cmbStoresIssueStockCode.NamingContainer as GridDataItem;
                    if (item != null)
                    {
     
                        (item["StoresIssueStockDesc"].FindControl("litStoresIssueStockDesc") as Literal).Text = stockItem.Text.Trim();
                        (item["StoresIssueUM"].FindControl("litStoresIssueUM") as Literal).Text = stockItem.Attributes["StockUM"];
     
                    }
                }
                #endregion
            }
    Hi!

    Good Day!

    I have almost the same issue, the event fires once an item has been selected but the SelectedIndex is always -1. I checked the number of items as well in the RadComboBox and it's zero.

    <telerik:RadComboBox ID="cmbStoresIssueStockCode" runat="server" AutoPostBack="true" DataSourceID="objStockItems" DataTextField="StockDesc" DataValueField="StockDesc" DropDownWidth="350px" EnableAutomaticLoadOnDemand="true" EnableVirtualScrolling="true" Filter="Contains" Height="300px" HighlightTemplatedItems="True" ItemsPerRequest="10" MarkFirstMatch="True" ShowMoreResultsBox="true" Skin="Windows7" Width="205px" onitemdatabound="cmbStoresIssueStockCode_ItemDataBound" onselectedindexchanged="cmbStoresIssueStockCode_SelectedIndexChanged">
                                            <HeaderTemplate>
                                                <table border="0" cellpadding="2" cellspacing="2" style="width: 100%">
                                                    <tr>
                                                        <td style="width: 70px;">
                                                            Stock Code
                                                        </td>
                                                        <td>
                                                            Description
                                                        </td>
                                                    </tr>
                                                </table>
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <table border="0" cellpadding="2" cellspacing="2" style="width: 100%">
                                                    <tr>
                                                        <td style="width: 70px;">
                                                            <%# DataBinder.Eval(Container.DataItem, "StockItemNo")%>
                                                        </td>
                                                        <td>
                                                            <%# DataBinder.Eval(Container.DataItem, "StockDesc")%>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </ItemTemplate>
                                        </telerik:RadComboBox>

    Here's the event code:


    Thanks,
    Noel
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2051 posts

    Posted 23 Jul 2013 Link to this post

    Hello,

    I would like to clarify that your observations are absolutely correct. If EnableAutomaticLoadOnDemand="true" when an item is selected only its text and value as plain text is send to the server. Therefore in the SelectedIndexChanged server-side event handler the RadComboBox items collection is empty and respectively the RadComboBox SelectedIndex property returns always "-1". As I mentioned earlier you could access the text and the value of the selected item as shown in the code snippet below:
    //code behind
    protected void ComboBoxAssetTag_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            //access the text value of the selected item
            string selectedItemText = e.Text;
            //access the value of the selected item
            string selectedItemValue = e.Value;
        }

    If we assume that you have mapped the Id column of your data source as item's value the e.Value will return the Id value of the selected item in the data source.

    Regards,
    Boyan Dimitrov
    Telerik
    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 the blog feed now.
Back to Top