Hello,
In my project, I open up a RadWindow that has 3 combo boxes, amoung other controls. The comboboxes are: RadComboBoxGrupos, RadComboBoxProjectos and RadComboBoxUser (TemplateItems with checkbox and label). The last two should be dependent on the first. When I want to postback, I can get the single selected values on the RadComboBoxGrupos and RadComboBoxProjectos comboboxes but I want to get all items in the templateItem box (RadComboBoxUser) and cycle through all of them see which ones have a checked checkbox. But I can't get the items, only if I specify a single selected item.
Any ideas on how to do this?
Here is my code:
Window aspx:
My code-behind:
Thanks in advanced,
Marco.
In my project, I open up a RadWindow that has 3 combo boxes, amoung other controls. The comboboxes are: RadComboBoxGrupos, RadComboBoxProjectos and RadComboBoxUser (TemplateItems with checkbox and label). The last two should be dependent on the first. When I want to postback, I can get the single selected values on the RadComboBoxGrupos and RadComboBoxProjectos comboboxes but I want to get all items in the templateItem box (RadComboBoxUser) and cycle through all of them see which ones have a checked checkbox. But I can't get the items, only if I specify a single selected item.
Any ideas on how to do this?
Here is my code:
Window aspx:
| <%@ Page Language="C#" AutoEventWireup="true" CodeFile="CreateCoordTaskForm.aspx.cs" Inherits="CreateTaskForm" %> |
| <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %> |
| <!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"> |
| <style type="text/css"> |
| .style1 |
| { |
| width: 233px; |
| } |
| .RadTreeView |
| { |
| white-space:nowrap; |
| cursor: default; |
| } |
| .RadTreeView_Hay |
| { |
| font:11px arial,verdana,sans-serif; |
| color:#000; |
| line-height:1.273em; |
| } |
| .RadTreeView .rtUL |
| { |
| zoom:1; |
| } |
| .RadTreeView .rtUL |
| { |
| margin:0; |
| padding:0; |
| } |
| .RadTreeView_Hay .rtLines .rtLast |
| { |
| background:none; |
| } |
| .RadTreeView_Hay .rtLines .rtFirst |
| { |
| background:url('mvwres://Telerik.Web.UI, Version=2008.3.1314.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4/Telerik.Web.UI.Skins.Hay.TreeView.FirstNodeSpan.gif') no-repeat 0 1.273em; |
| } |
| .RadTreeView_Hay .rtLines .rtLI |
| { |
| background:url('mvwres://Telerik.Web.UI, Version=2008.3.1314.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4/Telerik.Web.UI.Skins.Hay.TreeView.NodeSpan.gif') repeat-y 0 0; |
| } |
| .RadTreeView .rtLI |
| { |
| list-style-image: none; |
| list-style-position:outside; |
| list-style:none; |
| } |
| .RadTreeView_Hay .rtLines .rtLast .rtTop |
| { |
| background:url('mvwres://Telerik.Web.UI, Version=2008.3.1314.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4/Telerik.Web.UI.Skins.Hay.TreeView.SingleLine.gif') 0 0 no-repeat; |
| } |
| .RadTreeView_Hay .rtLines .rtTop |
| { |
| background:url('mvwres://Telerik.Web.UI, Version=2008.3.1314.35, Culture=neutral, PublicKeyToken=121fae78165ba3d4/Telerik.Web.UI.Skins.Hay.TreeView.TopLine.gif') 0 0 no-repeat; |
| } |
| div.RadTreeView_designtime .rtTop |
| { |
| position:relative; |
| } |
| .RadTreeView .rtTop |
| { |
| zoom:1; |
| } |
| .RadTreeView_Hay .rtTop |
| { |
| padding: 0 0 0 20px; |
| } |
| .RadTreeView .rtSp |
| { |
| display: -moz-inline-box; |
| display: inline-block; |
| width: 1px; |
| vertical-align: middle; |
| } |
| .RadTreeView_Hay .rtSp |
| { |
| height:21px; |
| } |
| .RadTreeView .rtIn |
| { |
| vertical-align:middle; |
| } |
| .RadTreeView_Hay .rtIn |
| { |
| padding: 3px 3px 4px; |
| } |
| .RadInput_Hay |
| { |
| font:12px arial,sans-serif; |
| } |
| .RadInput_Hay |
| { |
| vertical-align:middle; |
| } |
| .RadInput_Hay textarea |
| { |
| vertical-align:bottom; |
| overflow:auto; |
| } |
| .style2 |
| { |
| width: 337px; |
| } |
| </style> |
| </head> |
| <body> |
| <form id="form1" runat="server"> |
| <asp:ScriptManager ID="ScriptManager1" runat="server"> |
| </asp:ScriptManager> |
| <div> |
| <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> |
| <script type="text/javascript"> |
| function CloseAndRebind(args) { |
| GetRadWindow().Close(); |
| GetRadWindow().BrowserWindow.refreshGrid(args); |
| } |
| function GetRadWindow() { |
| var oWindow = null; |
| if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog |
| else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well) |
| return oWindow; |
| } |
| function CancelInsert() { |
| GetRadWindow().Close(); |
| } |
| function LoadProjectsAndUsers(combo, eventArqs) |
| { |
| projsCombo = $find("<%= RadComboBoxProjectos.ClientID %>"); |
| usersCombo = $find("<%= RadComboBoxUser.ClientID %>"); |
| var item = eventArqs.get_item(); |
| projsCombo.set_text("Carregando..."); |
| usersCombo.set_text("Carregando..."); |
| projsCombo.clearSelection(); |
| usersCombo.clearSelection(); |
| if (item.get_index() >= 0) |
| { |
| projsCombo.requestItems(item.get_value(), false); |
| usersCombo.requestItems(item.get_value(), false); |
| } |
| else |
| { |
| projsCombo.set_text(" Projectos "); |
| projsCombo.clearItems(); |
| usersCombo.set_text(" Utilizadores "); |
| usersCombo.clearItems(); |
| } |
| } |
| function DoTrackChanges(sender, eventArgs) |
| { |
| sender.trackChanges(); |
| } |
| function ItemsLoaded(combo, eventArqs) |
| { |
| if (combo.get_items().get_count() > 0) |
| { |
| combo.set_text(combo.get_items().getItem(0).get_text()); |
| combo.get_items().getItem(0).highlight(); |
| } |
| combo.showDropDown(); |
| combo.commitChanges(); |
| } |
| </script> |
| </telerik:RadCodeBlock> |
| <table style="border: 1px solid #000000; width:500px;"> |
| <tr> |
| <td class="style1" bgcolor="#CCFFCC" valign="top"> |
| <asp:Label ID="Label3" runat="server" Text="Tarefa: "></asp:Label> |
| <telerik:RadTextBox ID="RadTextBoxTaskName" Runat="server" |
| MaxLength="500" Rows="1" ToolTip="Nome Tarefa" Width="300px"> |
| </telerik:RadTextBox> |
| <asp:RequiredFieldValidator ID="ReqFieldValidatorName" runat="server" |
| ControlToValidate="RadTextBoxTaskName" |
| ErrorMessage="Deve especificar um nome para a tarefa."></asp:RequiredFieldValidator> |
| </td> |
| <td rowspan="2" class="style2" valign="top"> |
| <asp:Label ID="Label6" runat="server" Text="Grupos: "></asp:Label> |
| <telerik:RadComboBox ID="RadComboBoxGrupos" Runat="server" Skin="Hay" |
| DataSourceID="SqlDataSourceGrupos" DataTextField="nome_apps_grupos" |
| DataValueField="id_apps_grupos" EmptyMessage="Grupos" |
| LoadingMessage="Carregando..." AllowCustomText="True" Width="200px" |
| HighlightTemplatedItems="True" |
| onclientselectedindexchanging="LoadProjectsAndUsers" AutoPostBack="True" > |
| <CollapseAnimation Duration="200" Type="OutQuint" /> |
| </telerik:RadComboBox> |
| <asp:SqlDataSource ID="SqlDataSourceGrupos" runat="server" |
| ConnectionString="<%$ ConnectionStrings:DigitalGreenAppsConnectionString %>" |
| onselecting="SqlDataSourceGrupos_Selecting" SelectCommand="Proc_Apps_GetGroups" |
| SelectCommandType="StoredProcedure"> |
| <SelectParameters> |
| <asp:QueryStringParameter Name="userCod" QueryStringField="utiliz" |
| Type="String" DefaultValue="43" /> |
| <asp:QueryStringParameter Name="isAdmin" QueryStringField="admin" |
| Type="Boolean" DefaultValue="false" /> |
| </SelectParameters> |
| </asp:SqlDataSource> |
| <asp:Label ID="Label7" runat="server" Text="Projectos: "></asp:Label> |
| <telerik:RadComboBox ID="RadComboBoxProjectos" Runat="server" Skin="Hay" |
| DataTextField="titulo_apps_projectos" DataValueField="id_apps_projectos" |
| EmptyMessage="Projectos" LoadingMessage="Carregando..." |
| DataSourceID="SqlDataSourceProjectos" Width="200px" |
| HighlightTemplatedItems="True" |
| AllowCustomText="True" |
| onitemsrequested="RadComboBoxProjectos_ItemsRequested" |
| onclientitemsrequested="ItemsLoaded" |
| onclientitemsrequesting="DoTrackChanges"> |
| <CollapseAnimation Duration="200" Type="OutQuint" /> |
| </telerik:RadComboBox> |
| <asp:SqlDataSource ID="SqlDataSourceProjectos" runat="server" |
| ConnectionString="<%$ ConnectionStrings:AppsConnectionString %>" |
| SelectCommand="Proc_Apps_GetProjects" |
| SelectCommandType="StoredProcedure"> |
| <SelectParameters> |
| <asp:Parameter Name="groupID" Type="Int32" /> |
| <asp:QueryStringParameter DefaultValue="false" Name="isAdmin" |
| QueryStringField="admin" Type="Boolean" /> |
| </SelectParameters> |
| </asp:SqlDataSource> |
| </td> |
| </tr> |
| <tr> |
| <td class="style1" valign="top"> |
| <asp:Label ID="Label8" runat="server" Text="Destinitário:"></asp:Label> |
| <telerik:RadComboBox ID="RadComboBoxUser" Runat="server" Skin="Hay" |
| DataTextField="nome_utiliz" DataValueField="cod_utiliz" |
| EmptyMessage="Utilizadores" LoadingMessage="Carregando..." |
| DataSourceID="SqlDataSourceDestUsers" Width="200px" |
| HighlightTemplatedItems="True" |
| AllowCustomText="True" onitemsrequested="RadComboBoxUser_ItemsRequested" |
| onclientitemsrequested="ItemsLoaded" |
| onclientitemsrequesting="DoTrackChanges"> |
| <ItemTemplate> |
| <div onclick="StopPropagation(event)"> |
| <asp:CheckBox runat="server" ID="chk1" Checked="true"/> |
| <asp:Label runat="server" ID="Label1" AssociatedControlID="chk1"> |
| <%# Eval("nome_utiliz")%> |
| </asp:Label> |
| </div> |
| </ItemTemplate> |
| <CollapseAnimation Duration="200" Type="OutQuint" /> |
| </telerik:RadComboBox> |
| <asp:SqlDataSource ID="SqlDataSourceDestUsers" runat="server" |
| ConnectionString="<%$ ConnectionStrings:AppsConnectionString %>" |
| SelectCommand="Proc_Apps_GetUsersInGroup" SelectCommandType="StoredProcedure"> |
| <SelectParameters> |
| <asp:Parameter Name="groupID" Type="String" /> |
| </SelectParameters> |
| </asp:SqlDataSource> |
| <br /> |
| <asp:Label ID="Label5" runat="server" Text="Prioridade: "></asp:Label> |
| <telerik:RadComboBox ID="RadComboBoxPriority" Runat="server" |
| Skin="Hay" Text="Prioridade" Width="200px" LoadingMessage="Carregando..."> |
| <Items> |
| <telerik:RadComboBoxItem runat="server" BorderStyle="None" |
| ImageUrl="~/images/exclamation.png" Text="Urgent" Value="6" /> |
| <telerik:RadComboBoxItem runat="server" ImageUrl="~/images/flag_red.png" |
| Text="Muito Alto" Value="5" /> |
| <telerik:RadComboBoxItem runat="server" ImageUrl="~/images/flag_orange.png" |
| Text="Alto" Value="4" /> |
| <telerik:RadComboBoxItem runat="server" ImageUrl="~/images/flag_yellow.png" |
| Text="Normal" Value="3" Selected="True" /> |
| <telerik:RadComboBoxItem runat="server" ImageUrl="~/images/flag_green.png" |
| Text="Baixo" Value="2" /> |
| <telerik:RadComboBoxItem runat="server" ImageUrl="~/images/flag_blue.png" |
| Text="Muito Baixo" Value="1" /> |
| </Items> |
| <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
| </telerik:RadComboBox> |
| </td> |
| </tr> |
| <tr> |
| <td class="style1" bgcolor="#CCFFCC" valign="top"> |
| <asp:Label ID="Label1" runat="server" Text="Prazo: "></asp:Label> |
| <telerik:RadDateTimePicker ID="RadDateTimePickerDeadline" Runat="server" |
| MinDate="" Skin="Hay" FocusedDate=""> |
| <TimePopupButton ImageUrl="" HoverImageUrl=""></TimePopupButton> |
| <TimeView CellSpacing="-1" Culture="Portuguese (Portugal)"></TimeView> |
| <Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x" |
| Skin="Hay"></Calendar> |
| <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton> |
| </telerik:RadDateTimePicker> |
| <asp:RequiredFieldValidator ID="ReqFieldValidatorDeadline" runat="server" |
| ControlToValidate="RadComboBoxUser" |
| ErrorMessage="Deve especificar o prazo da tarefa."></asp:RequiredFieldValidator> |
| </td> |
| <td rowspan="2" class="style2" valign="top"> |
| </td> |
| </tr> |
| <tr> |
| <td class="style1" valign="top"> |
| <asp:Label ID="Label4" runat="server" Text="Notas:"></asp:Label> |
| <br /> |
| <telerik:RadTextBox ID="RadTextBoxNotes" Runat="server" |
| EmptyMessage="Pode especificar notas iniciais sobre a tarefa aqui..." Rows="20" |
| Skin="Hay" TextMode="MultiLine" Width="300px"> |
| </telerik:RadTextBox> |
| </td> |
| </tr> |
| <tr> |
| <td colspan="2" align="center" valign="middle" bgcolor="#66CCFF"> |
| <asp:CheckBox ID="CheckBoxValidar" runat="server" |
| Text="Validar Tarefa ao Criar" /> |
| </td> |
| </tr> |
| <tr> |
| <td colspan="2" bgcolor="#3399FF" align="center" valign="middle"> |
| <asp:LinkButton ID="LnkCreateTask" runat="server" Font-Bold="True" |
| Font-Underline="False" ForeColor="White" onclick="LnkValidateTask_Click"><img style="border: none 0px #000000" alt="Editar" src="images/add.png" /> Criar</asp:LinkButton> |
| <asp:LinkButton ID="LnkCancelCreate" runat="server" |
| Font-Bold="True" Font-Underline="False" ForeColor="White" |
| onclick="LnkCancelValidate_Click" CausesValidation="False"><img style="border: none 0px #000000" alt="Editar" src="images/cross.png" /> Cancelar</asp:LinkButton></td> |
| </tr> |
| </table> |
| </div> |
| <asp:SqlDataSource ID="SqlDataSourceInsert" runat="server" |
| ConnectionString="<%$ ConnectionStrings:DigitalGreenAppsConnectionString %>" |
| InsertCommand="Proc_Tarefas_CreateTask" InsertCommandType="StoredProcedure" |
| ProviderName="<%$ ConnectionStrings:AppsConnectionString.ProviderName %>" |
| SelectCommand="select * from tarefas_tarefas"> |
| <InsertParameters> |
| <asp:ControlParameter ControlID="CheckBoxValidar" Name="valid" |
| PropertyName="Checked" Type="Boolean" /> |
| <asp:ControlParameter ControlID="RadComboBoxUser" Name="utiliz" |
| PropertyName="SelectedValue" Type="String" /> |
| <asp:QueryStringParameter Name="autor" QueryStringField="utiliz" |
| Type="String" /> |
| <asp:ControlParameter ControlID="RadDateTimePickerDeadline" Name="prazo" |
| PropertyName="SelectedDate" Type="DateTime" /> |
| <asp:ControlParameter ControlID="RadTextBoxTaskName" Name="nome" |
| PropertyName="Text" Type="String" /> |
| <asp:ControlParameter ControlID="RadTextBoxNotes" Name="notas" |
| PropertyName="Text" Type="String" /> |
| <asp:ControlParameter ControlID="RadComboBoxPriority" Name="prioridade" |
| PropertyName="SelectedValue" Type="Byte" /> |
| <asp:ControlParameter ControlID="RadTreeViewCategorias" Name="categoria" |
| PropertyName="SelectedValue" Type="Int32" /> |
| <asp:ControlParameter ControlID="RadComboBoxGrupos" Name="grupo" |
| PropertyName="SelectedValue" Type="Int32" /> |
| <asp:ControlParameter ControlID="RadComboBoxProjects" Name="projecto" |
| PropertyName="SelectedValue" Type="Int32" /> |
| </InsertParameters> |
| </asp:SqlDataSource> |
| </form> |
| </body> |
| </html> |
My 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.HtmlControls; |
| using System.Web.UI.WebControls; |
| using System.Web.UI.WebControls.WebParts; |
| using System.Xml.Linq; |
| using Telerik.Web.UI; |
| public partial class CreateTaskForm : System.Web.UI.Page |
| { |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| DateTime now = DateTime.Now; |
| RadDateTimePickerDeadline.FocusedDate = now; |
| RadDateTimePickerDeadline.MinDate = now; |
| RadDateTimePickerDeadline.SelectedDate = now; |
| } |
| protected void LnkCancelValidate_Click(object sender, EventArgs e) |
| { |
| ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CancelInsert();", true); |
| } |
| protected void LnkValidateTask_Click(object sender, EventArgs e) |
| { |
| string users = ""; |
| RadComboBox box = RadComboBoxUser; |
| foreach (RadComboBoxItem i in box.Items) |
| { |
| if (((CheckBox)i.FindControl("chk1")).Checked) |
| users = String.Concat(users,", "); |
| } |
| //int result = SqlDataSourceInsert.Insert(); |
| ClientScript.RegisterStartupScript(Page.GetType(), "mykey", "CloseAndRebind();", true); |
| } |
| protected void SqlDataSourceGrupos_Selecting(object sender, SqlDataSourceSelectingEventArgs e) |
| { |
| e.Command.Parameters[0].Value = this.User.Identity.Name; |
| //e.Command.Parameters[1].Value = Cache["admin"]; |
| } |
| protected void RadComboBoxProjectos_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) |
| { |
| SqlDataSourceProjectos.SelectParameters[0].DefaultValue = e.Text; |
| RadComboBoxProjectos.DataBind(); |
| } |
| protected void RadComboBoxUser_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e) |
| { |
| SqlDataSourceDestUsers.SelectParameters[0].DefaultValue = e.Text; |
| RadComboBoxUser.DataBind(); |
| } |
| } |
Thanks in advanced,
Marco.