Hi Team,
I am not able to retain value of combobox when i click on "Click Me" in my code. Please help me. My code as below.
Code Behind Code:-
| Partial Class _Default |
| Inherits System.Web.UI.Page |
| Protected Sub rcbSections_ItemDataBound(ByVal sender As Object, ByVal e As RadComboBoxItemEventArgs) Handles rcbCat.ItemDataBound |
| Dim CustomExamID As String = CType(e.Item.FindControl("chk"), CheckBox).Attributes("CategoryID") |
| If ViewState("CategoryID") <> CustomExamID Then |
| ViewState("CategoryID") = CustomExamID |
| Dim CustomExamTitle As String = CType(e.Item.FindControl("chk"), CheckBox).Attributes("CategoryName") |
| Dim objSectionItem As New RadComboBoxItem |
| objSectionItem.Value = CustomExamID |
| objSectionItem.Text = CustomExamTitle |
| objSectionItem.IsSeparator = True |
| rcbCat.Items.Insert(e.Item.Index, objSectionItem) |
| rcbCat.Items(e.Item.Index - 1).Controls.Remove(rcbCat.Items(e.Item.Index - 1).FindControl("chk")) |
| Dim objTitle As New LiteralControl() |
| objTitle.ID = "lcCategoryName" |
| objTitle.Text = CustomExamTitle |
| rcbCat.Items(e.Item.Index - 1).Controls.Add(objTitle) |
| End If |
| End Sub |
| Private Sub FillCategory() |
| Dim dtMaster As New DataTable("Item") |
| dtMaster.Columns.Add("CategoryID") |
| dtMaster.Columns.Add("CategoryName") |
| dtMaster.Columns.Add("SubCategoryID") |
| dtMaster.Columns.Add("SubCategoryName") |
| For index As Integer = 1 To 10 |
| For index1 As Integer = 1 To 3 |
| Dim drNew As DataRow |
| drNew = dtMaster.NewRow() |
| drNew("CategoryID") = index |
| drNew("CategoryName") = "CategoryName" + index.ToString |
| drNew("SubCategoryID") = index1 |
| drNew("SubCategoryName") = "SubCategoryName" + index1.ToString |
| dtMaster.Rows.Add(drNew) |
| Next |
| Next |
| rcbCat.DataSource = dtMaster |
| rcbCat.DataTextField = "SubCategoryName" |
| rcbCat.DataValueField = "SubCategoryID" |
| rcbCat.DataBind() |
| End Sub |
| Protected Sub btnFillCat_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFillCat.Click |
| FillCategory() |
| End Sub |
| End Class |
Design Code :-
| <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %> |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml"> |
| <head runat="server"> |
| <title></title> |
| </head> |
| <telerik:radscriptblock runat="server" id="scriptBlock"> |
| <script type="text/javascript"> |
| var cancelDropDownClosing = false; |
| function onDropDownClosing() { |
| cancelDropDownClosing = false; |
| } |
| function onSectionCheckBoxClick() { |
| var combo = $find("<%= rcbCat.ClientID %>"); |
| //prevent second combo from closing |
| cancelDropDownClosing = true; |
| //holds the text of all checked items |
| var text = ""; |
| //holds the values of all checked items |
| var values = ""; |
| //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 + "_chk"); |
| if (chk1) { |
| if (chk1.checked) { |
| text += item.get_text() + ","; |
| values += item.get_value() + ","; |
| } |
| } |
| } |
| //remove the last comma from the string |
| text = removeLastComma(text); |
| values = removeLastComma(values); |
| if (text.length > 0) { |
| //set the text of the combobox |
| combo.set_text(text); |
| combo.set_value(values); |
| } |
| else { |
| //all checkboxes are unchecked |
| //so reset the controls |
| combo.set_text("All Category"); |
| combo.set_value("All"); |
| } |
| } |
| function StopPropagation(e) { |
| if (!e) { |
| e = window.event; |
| } |
| e.cancelBubble = true; |
| } |
| //this method removes the ending comma from a string |
| function removeLastComma(str) { |
| return str.replace(/,$/, ""); |
| } |
| </script> |
| </telerik:radscriptblock> |
| <body> |
| <form id="form1" runat="server"> |
| <div> |
| <div style="color: Red;width:500px;text-align:justify;"> |
| <b>Note:- </b> First Fill the Combobox by clicking on "Fill Category" then select calegories |
| from combobox using checkbox. After this click on "Click Me". Then open the combobox |
| you will see the Separator have checkbox and category name will disapper. |
| </div> |
| <br /> |
| <asp:Button runat="server" Text="Fill Category" ID="btnFillCat" /><br /><br /> |
| <asp:Button runat="server" Text="Click Me" ID="btnClick" /> |
| <br /> |
| <br /> |
| <br /> |
| <telerik:radcombobox id="rcbCat" runat="server" height="140px" showtoggleimage="True" |
| highlighttemplateditems="true" onclientload="onSectionCheckBoxClick" width="290px" |
| style="vertical-align: middle;" expandanimation-type="None" collapseanimation-type="None" |
| allowcustomtext="false" onclientdropdownclosed="onDropDownClosing"> |
| <ItemTemplate> |
| <div onclick="StopPropagation(event)"> |
| <asp:CheckBox runat="server" ID="chk" Text='<%# Eval("SubCategoryName") %>' Value='<%# Eval("SubCategoryID") %>' |
| CategoryID='<%# Eval("CategoryID") %>' CategoryName='<%# Eval("CategoryName") %>' |
| TextAlign="right" onclick="onSectionCheckBoxClick()" /> |
| </div> |
| </ItemTemplate> |
| </telerik:radcombobox> |
| </div> |
| <telerik:radajaxmanager runat="server" id="ramTest"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="rcbCat"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="rcbCat" LoadingPanelID="rlpCR" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:radajaxmanager> |
| </form> |
| </body> |
| </html> |
I am waiting for you reply.
Thanks
Chirag Patel