So I have a simple RadWindow setup like so:
<telerik:RadWindow ID="rwCreateChecklist" runat="server" Width="300px" Height="150px" Behaviors="Move,Close" Title="Create Checklist" VisibleStatusbar="false" Modal="true"> <ContentTemplate> <div class="wndCreateChecklist"> <div class="row"> <label> Reference Number:</label> <telerik:RadTextBox ID="txtReferenceNumber" runat="server" Width="80px" MaxLength="50"> </telerik:RadTextBox> <asp:RequiredFieldValidator ID="reqReferenceNumber" runat="server" Text="Required" ValidationGroup="CreateChecklist" ControlToValidate="txtReferenceNumber" SkinID="noFloat"></asp:RequiredFieldValidator> </div> <div class="button-row"> <telerik:RadButton ID="btnCreateChecklist" runat="server" Text="Create Checklist" ValidationGroup="CreateChecklist"> </telerik:RadButton> <telerik:RadButton ID="btnCancel" runat="server" Text="Cancel"> </telerik:RadButton> </div> </div> </ContentTemplate> </telerik:RadWindow><asp:Panel runat="server" ID="NumericPagerPlaceHolder" />protected void HandleOnItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridPagerItem) { var gridPager = e.Item as GridPagerItem; var numericPagerControl = gridPager.GetNumericPager(); var placeHolder = gridPager.FindControl("NumericPagerPlaceHolder"); placeHolder.Controls.Add(numericPagerControl); } }<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> <script type="text/javascript"> var tableView = null; function pageLoad(sender, args) { tableView = $find("<%= TransactionsGrid.ClientID %>").get_masterTableView(); } function changePage(argument) { tableView.page(argument); } </script> </telerik:RadScriptBlock>Private Sub rgC_PreRender(sender As Object, e As System.EventArgs) Handles rgC.PreRender If Not IsPostBack Then For Each item As GridItem In rgC.MasterTableView.Items If (TypeOf item Is GridDataItem) Then Dim lblEmpId As Label = CType(item.FindControl("lblEmpId"), Label) Dim lblEmpNo As Label = CType(item.FindControl("lblEmpNo"), Label) 'Contains the null value if invalid Dim lblJobCode As Label = CType(item.FindControl("lblJobCode"), Label) Dim lblJobNum As Label = CType(item.FindControl("lblJobNum"), Label) 'Contains the null value if invalid Dim lblCardId As Label = CType(item.FindControl("lblCardId"), Label) If (lblEmpNo.Text = "") Then lblCardId.ForeColor = Drawing.Color.Red item.Edit = True End If If (lblJobCode.Text = "") Then lblCardId.ForeColor = Drawing.Color.Red item.Edit = True End If End If Next rgC.Rebind() End If End SubI’m using a RadComboBox where a user can select multiple items and save them against a news article.
When the user visits back I need to be able to pre-populate all of the items which were previously saved against the article.
I’m trying to work out how to set multiple items as selected, from what I can see you can only ever set one.
Something like this:
RadComboBoxItem _item1 = new RadComboBoxItem(); _item1.Value = "1"; _item1.Text = "One"; _item1.Selected = true; RadComboBoxItem _item2 = new RadComboBoxItem(); _item2.Value = "2"; _item2.Text = "Two"; _item2.Selected = true; RadComboBox _radComboBox = new RadComboBox(); _radComboBox.Items.Add(_item1); _radComboBox.Items.Add(_item2);
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if ((e.Item is GridEditableItem || e.Item is GridDataItem) && e.Item.IsInEditMode) { GridEditableItem editForm = (GridEditableItem)e.Item; (editForm.FindControl("ddlGridAdjBy") as DropDownList).SelectedValue = ((System.Data.DataRowView)(editForm.DataItem)).Row.ItemArray[1].ToString(); // throws an exception here } }protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e){ if (e.Item is GridEditableItem && (e.Item as GridEditableItem).IsInEditMode) { GridEditFormItem editItem = (GridEditFormItem)e.Item; RadComboBox dropdownUOM = (RadComboBox)editItem.FindControl("editList"); // This PopulateDropDown works in populating the control with items // //For Each item As Something In CollectionThatGetsIterated // Dim NewListItem As New RadComboBoxItem() // NewListItem.Text = GetLocalizedText(item.Something1, item.Something2) // NewListItem.Value = GetValue(item.Value) // theDropDownControl.Items.Add(NewListItem) //Next PopulateDropDown(21, dropdownUOM); dropdownUOM.DataBind(); }}// This is what sets the item and edit templates. Since the items in the dropdown are added to the Items collection in a loop vs. against a dataset/collection the ListTextField and ListValueFields are not set. private void BuildLookupListColumn(string columnName, GridTemplateColumn existingTemplateColumn){ existingTemplateColumn.ItemTemplate = new CustomItemTemplate(columnName); KeyValuePair<string, string> emptyListItem = new KeyValuePair<string, string>("Select", string.Empty); existingTemplateColumn.EditItemTemplate = new CustomEditTemplate(columnName, emptyListItem); existingTemplateColumn.ConvertEmptyStringToNull = true;}public class CustomEditTemplate: ITemplate, IBindableTemplate{ private string _columnName; private KeyValuePair<string, string> _emptyListItem; public CustomEditTemplate() { } public CustomEditTemplate(string columnName, KeyValuePair<string, string> emptyListItem) { this.ColumnName = columnName; } public string ColumnName { get { return _columnName; } set { _columnName = value; } } public KeyValuePair<string, string> EmptyListItem { get { return _emptyListItem; } set { _emptyListItem = value; } } public void InstantiateIn(Control container) { RadComboBox displayControl = new RadComboBox(); displayControl.ID = "editList"; displayControl.DataBinding += DisplayControl_DataBinding; container.Controls.Add(displayControl); } private void DisplayControl_DataBinding(object sender, EventArgs e) { //Dim target As RadComboBox = DirectCast(sender, RadComboBox) //Dim container As GridEditFormItem = DirectCast(target.NamingContainer, GridEditFormItem) //Dim displayControl As RadComboBox = DirectCast(sender, RadComboBox) //'Note: This line below throws a binding error on insert DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'AccountSettings'. //displayControl.SelectedValue = DataBinder.Eval(container.DataItem, ColumnName).ToString() //displayControl.SelectedValue = displayControl.SelectedValue } public System.Collections.Specialized.IOrderedDictionary ExtractValues(Control container) { OrderedDictionary dict = new OrderedDictionary(); string value; value = (((RadComboBox)((GridEditFormItem)container).FindControl("editList")).SelectedValue); dict.Add(ColumnName, value); return dict; }}public class CustomItemTemplate : ITemplate{ private string _columnName; public CustomItemTemplate() { } public CustomItemTemplate(string columnName) { this.ColumnName = columnName; } public string ColumnName { get { return _columnName; } set { _columnName = value; } } public void InstantiateIn(Control container) { LiteralControl displayControl = new LiteralControl(); displayControl.ID = "litEditList"; displayControl.DataBinding += DisplayControl_DataBinding; container.Controls.Add(displayControl); } private void DisplayControl_DataBinding(object sender, EventArgs e) { LiteralControl target = (LiteralControl)sender; GridDataItem container = (GridDataItem)target.NamingContainer; target.Text = (DataRowView)container.DataItem(_columnName).ToString(); }}I'm working on a project for a client, where the app I'm building will serve to edit an XML file consumed by a live application. The application is written in Flash, and quite unstable, so I am kind of stuck with the less than optimal XML setup.
The XML is made up (simplified) like the following:
<MenuItem id="1" label="category1"> <Description>Description for Category 1</Description> <Image>Image for category 1</Image> <Item label ="Category1Item1"> <Price>12.99</Price> <Type>Wood</Type> <additionalElementsHere /> </Item> <Item label ="Category1Item2"> <Price>112.99</Price> <Type>Stone</Type> <additionalElementsHere /> </Item> <AdditionalItemsHere /> </MenuItem> <AdditionMenuITemsHere />
I've been using a Telerik treeview bound to an XMLDataSource to display the data and allow users to interact with it (add/delete nodes, move nodes by means of drag and drop, or copy nodes and the underlying elements). So far, so good.
Now my client would like to know if it is somehow possible to use the <Type> Element of the Item elements as grouping containers.
So currently the treeview looks like this:
category1
--Category1Item1
--Category1Item2
And ideally, it should end up looking like this:
category1
--Wood
----Category1Item1
----Category1Item123
--Stone
----Category1Item2
----Category1Item456
I read up on HierarchicalDataTemnplates, but have not managed to figure out if these work in the ASP.NET controls supplied by Telerik. I would like to try and stick to what I have so far, as many hours of work have already gone into the product so far.
I'd appreciate it if someone could point me in the right direction of how to tackle this particular issue.
Thanks in advance :)
Peter