mercredi 23 décembre 2015

Access checkbox in a RadComboBox Itemtemplate in RadGrid

I have a RadGrid, which has a RadComboBox in ItemTemplate, and the RadComboBox has a asp:Checkbox and label in its itemtemplate. The LoadOnDemand for RadComboBox is true. Whenever a checkbox is checked/unchecked, i need to update the radcombobox text, which i need to generate at runtime at client side. Below is the code snippet

                                                        <HeaderStyle HorizontalAlign="Center" VerticalAlign="Top" />
                                                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" />
                                                        <ItemTemplate>
                                                            <telerik:RadComboBox ID="rcbTechnician" runat="server" EnableLoadOnDemand="true"
                                                                EmptyMessage="Select Technician" HighlightTemplatedItems="true" EnableEmbeddedSkins="false"
                                                                OnClientItemsRequesting="rcbTechnician_ClientItemsRequesting"
                                                                OnItemDataBound="rcbTechnician_ItemDataBound"
                                                                OnItemsRequested="rcbTechnician_ItemsRequested"
                                                                DropDownWidth="340px" ShowMoreResultsBox="true"
                                                                AllowCustomText="true" Width="250px" Height="300px"
                                                                ForeColor="Purple">    
                                                                <ItemTemplate>
                                                                    <div onclick="StopPropagation(event)" class="combo-item-template">
                                                                        <asp:CheckBox runat="server" ID="chkTech" onclick="onCheckBoxClickTech(this)"/>
                                                                        <asp:Label runat="server" ID="lblTech" AssociatedControlID="chkTech">
                                                                            <%# DataBinder.Eval(Container.DataItem, "NameAlpha")%>
                                                                        </asp:Label>
                                                                    </div>
                                                                 </ItemTemplate>                                                                                                                                 
                                                            </telerik:RadComboBox>
                                                            <telerik:RadTextBox ID="lblSlctTechnicianValue" runat="server" style="visibility:hidden" />

                                                           <telerik:RadScriptBlock ID="RadScriptBlockForTechinician" runat="server">
                                                                <script type="text/javascript">
                                                                    function onCheckBoxClickTech(chk) {
                                                                        debugger;

                                                                        var text = "", values = "";
                                                                        var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
                                                                        var combo = $find('<%# ((GridItem)Container).FindControl("rcbTechnician").ClientID %>');
                                                                        var hdnVal = $find('<%# ((GridItem)Container).FindControl("lblSlctTechnicianValue").ClientID %>'); 
                                                                        //get the collection of all items
                                                                        var items = combo.get_items();
                                                                        //enumerate all items
                                                                        for (var i = 0; i < items.get_count(); i++) {
                                                                            var item = items.getItem(i);
                                                                            //get the checkbox element of the current item
                                                                            var chk1 = $get(combo.get_id() + "_i" + i + "_chkTech");
                                                                            if (chk1.checked) {
                                                                                text += item.get_text() + ";";
                                                                                values += item.get_value() + ",";
                                                                            }
                                                                        }

                                                                        //remove the last comma from the string
                                                                        text = removeLastComma1(text);
                                                                        values = removeLastComma1(values);
                                                                        combo.set_text(text);
                                                                        hdnVal.set_value(values);                                                                           
                                                                    }

                                                                    function removeLastComma1(str) {
                                                                        return str.replace(/,$/, "");
                                                                    }                                                       
                                                                    </script>
                                                            </telerik:RadScriptBlock>
                                                        </ItemTemplate>

                                                       </telerik:GridTemplateColumn>

The problem is that whenever the checkbox change event occurs, it always refers to the same row. so the combobox that it finds is always ctl00_ContentPlaceHolder1_rgSelectedTools_ctl00_ctl06_rcbTechnician for each row in the grid. Which results in incorrect updation.

I have been stuck on this for many days. Can someone point out the correct way to do this..

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire