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

Combobox in grid not firing items req if populated

1 Answer 46 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
rik butcher
Top achievements
Rank 1
rik butcher asked on 17 Apr 2013, 07:14 PM
hey Guys - i've got a bit of a head scratcher here. i've got a combobox on a grid. i bind it on item databind. if the box comes up empty - no problem - you just click and it'll go get the list and fires the server method: OnItemsRequested.

the weird part is - if the combobox has data in it - it doesn't fire the OnItemsRequested event, but i can clear out the contents and it fires just fine.
is there something i'm missing here? it's got to be something simple. i've included partial markup for the grid - the databind method & the combobox method.
any help is totally appreciated.
thanks
rik

RAD GRID MARKUP:::

 

<telerik:RadGrid ID="WorkOrderItemsRadGrid" runat="server" AllowPaging="true" AutoGenerateColumns="false"

                        Skin="WebBlue" PageSize="8" EnableTheming="false" AllowFilteringByColumn="false" AllowCustomPaging="false"

                        OnItemDataBound="WorkOrderItemsRadGrid_ItemDataBound" OnNeedDataSource="WorkOrderItemsRadGrid_NeedDataSource"

                        Width="100%" OnItemCreated="WorkOrderItemsRadGrid_ItemCreated" AllowMultiRowSelection="true">

                        <GroupingSettings CaseSensitive="false" />

                        <PagerStyle Mode="NextPrevAndNumeric" />

                        <MasterTableView DataKeyNames="WORKORDERNUMBER,LOCATIONID,WORKORDERID,WORKORDERDETAILID,WOTYPENAME,LASTUPDATED,RACKNUMBER,LASTUPDATEDBY,MATERIALTYPE,MATERIALTYPEID,MATERIALDESCRIPTION"

                         CommandItemSettings-ShowAddNewRecordButton="false" EditMode="PopUp" CommandItemDisplay="Top"

                        AllowSorting="true" CommandItemSettings-RefreshText="Refresh" CommandItemSettings-RefreshImageUrl="~/App_Themes/GOLD Main/ToolBar/refresh_16x16.gif" >

                            <HeaderStyle HorizontalAlign="Left" />

                            <Columns>

                                <telerik:GridTemplateColumn AllowFiltering="false" HeaderStyle-Width="100px" UniqueName="RackNumberColumn"

                                    ItemStyle-HorizontalAlign="Left" ItemStyle-Width="100px" HeaderText="Rack">

                                    <ItemTemplate>

                                        <telerik:RadComboBox ID="RackNumberGridComboBox" runat="server" Width="90px" Height="160px"

                                            Skin="WebBlue" EnableLoadOnDemand="true" AutoPostBack="true" OnItemsRequested="RackNumberGridComboBox_ItemsRequested"

                                            AllowCustomText="false" HighlightTemplatedItems="true" DataValueField="RACKID"

                                            DataTextField="RACKNUMBER" DropDownWidth="210px">

                                            <HeaderTemplate>

                                                <ul class="woCustomerDropDown" style="width: 180px;">

                                                    <li class="woCustomerCol" style="width: 120px;">Rack Number</li>

                                                    <li class="woCustomerCol" style="width: 60px;">Utilization</li>

                                                </ul>

                                            </HeaderTemplate>

                                            <ItemTemplate>

                                                <ul class="woCustomerDropDown" style="width: 180px;">

                                                    <li class="woCustomerCol" style="width: 120px;">

                                                        <%# DataBinder.Eval(Container.DataItem, "RACKNUMBER") %></li>

                                                    <li class="woCustomerCol" style="width: 60px;">

                                                        <%# DataBinder.Eval(Container.DataItem, "UTILIZATION") %></li>

                                                </ul>

                                            </ItemTemplate>

                                        </telerik:RadComboBox>

                                    </ItemTemplate>

                                </telerik:GridTemplateColumn>

                                <telerik:GridBoundColumn DataField="WORKORDERITEMDISPLAY" HeaderText="Work Order"

                                    HeaderStyle-Width="80px" FilterControlWidth="60px" />

                               

                            </Columns>

                        </MasterTableView>

                    </telerik:RadGrid>

RAD GRID DATABIND:

protected void WorkOrderItemsRadGrid_ItemDataBound(object sender, GridItemEventArgs e)

        {

            GridCommandItem cmndItem = (GridCommandItem)WorkOrderItemsRadGrid.MasterTableView.GetItems(GridItemType.CommandItem)[0];

            LinkButton btn = (LinkButton)cmndItem.FindControl("RebindGridButton");

            ((System.Web.UI.WebControls.TableCell)(btn.Parent)).HorizontalAlign = HorizontalAlign.Left;

 

            if (e.Item is GridDataItem)

            {

                GridDataItem boundItem = (GridDataItem)e.Item;

                string wonumber = Convert.ToString(boundItem.OwnerTableView.DataKeyValues[boundItem.ItemIndex]["WORKORDERNUMBER"]);

                string woid = Convert.ToString(boundItem.OwnerTableView.DataKeyValues[boundItem.ItemIndex]["WORKORDERID"]);

                string locationid = Convert.ToString(boundItem.OwnerTableView.DataKeyValues[boundItem.ItemIndex]["LOCATIONID"]);

                string wodetailid = Convert.ToString(boundItem.OwnerTableView.DataKeyValues[boundItem.ItemIndex]["WORKORDERDETAILID"]);

                string lastracknumber = Convert.ToString(boundItem.OwnerTableView.DataKeyValues[boundItem.ItemIndex]["RACKNUMBER"]);

                string lastrackid = Convert.ToString(boundItem.OwnerTableView.DataKeyValues[boundItem.ItemIndex]["RACKID"]);

                string lastupdate = Convert.ToString(boundItem.OwnerTableView.DataKeyValues[boundItem.ItemIndex]["LASTUPDATED"]);

                string lastupdateby = Convert.ToString(boundItem.OwnerTableView.DataKeyValues[boundItem.ItemIndex]["LASTUPDATEDBY"]);

                int materialtypeid = Convert.ToInt32(boundItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["MATERIALTYPEID"]);

                string materialdesc = boundItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["MATERIALDESCRIPTION"].ToString();

 

                if (lastracknumber != "")

                {

             RadComboBox rackBox = boundItem.FindControl("RackNumberGridComboBox") as RadComboBox;

 

                    using (TruckingBC tbc = new TruckingBC())

                    {

rackBox.DataSource = tbc.GetRackNumbers(DivisionID,lastracknumber);

                          rackBox.DataBind();

                                            }

                }

 

        }

 

 

 

COMBO BOX ON GRID EVENTS:

 

 

protected void RackNumberGridComboBox_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)

        {

            RadComboBox comboBox = (RadComboBox)sender;

            using (TruckingBC tbc = new TruckingBC())

            {

                comboBox.DataSource = tbc.GetRackNumbers(DivisionID);

                comboBox.DataBind();

            }

        }

 

 

1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 22 Apr 2013, 02:28 PM
Hi Rik,

The ItemsRequested event occurs when the EnabledLoadOnDemand property is True and the user types/deletes text in the input field or clicks on the drop-down toggle image when the list is empty.

According to your code this event will be fired only if you change the text in the combo's input. Also you set AutoPostBack to true which will fire SelectedIndexChanged event if you subscribe for it, but it will not fire ItemsRequested. To do that set AutoPostBack to false, handle OnClientSelectedIndexChanged event:

<telerik:RadComboBox ID="RackNumberGridComboBox" runat="server" Width="90px" Height="160px" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"
    Skin="WebBlue" EnableLoadOnDemand="true" AutoPostBack="false" OnItemsRequested="RackNumberGridComboBox_ItemsRequested"
    OnSelectedIndexChanged="RackNumberGridComboBox_SelectedIndexChanged"
    AllowCustomText="false" HighlightTemplatedItems="true" DataValueField="RACKID"
    DataTextField="RACKNUMBER" DropDownWidth="210px">
    <HeaderTemplate>
        <ul class="woCustomerDropDown" style="width: 180px;">
            <li class="woCustomerCol" style="width: 120px;">Rack Number</li>
            <li class="woCustomerCol" style="width: 60px;">Utilization</li>
        </ul>
    </HeaderTemplate>
    <ItemTemplate>
        <ul class="woCustomerDropDown" style="width: 180px;">
            <li class="woCustomerCol" style="width: 120px;">
                <%# DataBinder.Eval(Container.DataItem, "RACKNUMBER") %></li>
            <li class="woCustomerCol" style="width: 60px;">
                <%# DataBinder.Eval(Container.DataItem, "UTILIZATION") %></li>
        </ul>
    </ItemTemplate>
</telerik:RadComboBox>

and call requestItems() method:
function OnClientSelectedIndexChanged(sender, args) {
    sender.requestItems();
}

Kind regards,
Hristo Valyavicharski
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
rik butcher
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or