Data Binding to an XML file - c#

I have an XML file structured as follows:
<Levels>
<Level Code="T" Text="Test">
<SubLevels>
<SubLevel Type="9" Text="Nine"/>
<SubLevel Type="8" Text="Eight"/>
<SubLevel Type="7" Text="Seven"/>
<SubLevel Type="6" Text="Six"/>
</SubLevels>
</Level>
<Level Code="T2" Text="Test 2">
<SubLevels>
<SubLevel Type="1" Text="One"/>
<SubLevel Type="2" Text="Two"/>
</SubLevels>
</Level>
</Levels>
What I want is two drop down lists, one linked to /Levels/Level and one to the SubLevels for the selected level. Currently, I have the main one bound as follows:
<asp:XmlDataSource ID="XmlLevelInfo" runat="server" DataFile="~/Levels.xml">
</asp:XmlDataSource>
<asp:DropDownList ID="cboLevelFilter" runat="server"
DataSourceID="XmlLevelInfo" DataTextField="Text" DataValueField="Code">
</asp:DropDownList>
This works fine, but I can’t work out how to link the Sub Levels to the second drop down list. Is this possible using data binding?

I would expect that the XmlDataSource for your second drop-down would need to have it's XPath varied on SelectedItemChanged of the first.
Such that it's XPath might look like:
//Level[#Code = '<CODE VALUE FROM SELECTED ITEM>']//SubLevel
You'd probably also want to initially just bind it with all SubLevels such that the XPath might look like: //SubLevel
Then it'll take a little extra effort to AJAX-ify it all for a nice experience... (Don't forget to set AutoPostBack to true on the first drop-down!)

Related

DevExpress XtraGrid v12.2 GetTotalSummary

I am implementing IListServer. Everything works fine except GetTotalSummary. All examples that I've been able to find show the implementation of GetTotalSummary returning a Dictionary of items. In version 12, the interface for IListServer has changed and no longer returns a dictionary. Instead, it returns a List<objects>.
An example implementation of the interface is given here, but unfortunately the specific method that I need is not implemented.
I don't know how to fill this returning list so that I can see my records' count in grid footer. Any help is really appreciated :)
And here is my ascx for the dynamic grid I am filling:
<dx:ASPxGridView runat="server" Width="100%" ID="grdMain" ClientInstanceName="grid"
KeyFieldName="ID" AutoGenerateColumns="false" EnableRowsCache="false"
OnAutoFilterCellEditorCreate="grid_AutoFilterCellEditorCreate" OnAutoFilterCellEditorInitialize="grid_AutoFilterCellEditorInitialize" OnProcessColumnAutoFilter="grid_ProcessColumnAutoFilter">
<settingsbehavior allowfocusedrow="true" allowclienteventsonload="false" AllowGroup="false" autoexpandallgroups="true"
enablerowhottrack="True" columnresizemode="Control" />
<settings showverticalscrollbar="true" verticalscrollableheight="500" showgrouppanel="false"
showfilterrow="true" ShowHorizontalScrollBar="True" showfooter="True"/>
<styles>
<AlternatingRow Enabled="true" />
<Row Cursor="pointer" />
</styles>
<clientsideevents init="SGEntityListScript.OnInit" endcallback="SGEntityListScript.OnEndCallback" />
<SettingsBehavior EnableCustomizationWindow="true" />
<TotalSummary>
<dx:ASPxSummaryItem FieldName="ID" SummaryType="Count"/>
</TotalSummary>
</dx:ASPxGridView>
The last parameter of the IListServer.Apply method is the list of total summary descriptions requested by the control. Save them locally or immediately evaluate and save results. The GetTotalSummary method should return array of total summary values in the same order as they were requested in the Apply method.

Populating a treeView from XMLDataSource in C#, but nothing is visible on the UI

Aspx
<asp:XmlDataSource runat="server" ID="TreeXml" EnableViewState="false" EnableCaching="false" />
<asp:TreeView ID="SelectTree" runat="server" DataSourceID="projectsTreeXml" AutoGenerateDataBindings="false">
<DataBindings>
<asp:TreeNodeBinding DataMember="A" TextField="DisplayID" ValueField="ID"/>
<asp:TreeNodeBinding DataMember="B" TextField="DisplayID" ValueField="ID" />
</DataBindings>
</asp:TreeView>
C# code
TreeXml.Data = getXMLString();
TreeXml.DataBind();
SelectCtrlTree.DataBind();
When I debug, the SelectTree has the dataSource successfully populated after DataBind() call, but the Nodes element is null, I think that should be ok.
The get getXMLString returns String
<?xml version="1.0" encoding="UTF-8" ?>
- <Root>
- <A ID="3063" Name="All Initiatives" DisplayID="Enterprise">
<B ID="4911" Name="Closed - 2" DisplayID="Closed - 2"/>
- <A ID="17902" Name="Corporate Programs" DisplayID="Corporate">
- <A ID="25920" Name="In-flight Projects" DisplayID="In-flight">
<B ID="3688" Name="Cash Flow BI Project" DisplayID="CORP00712" />
</A>
</A>
</A>
</Root>
Have no clue why the UI does not show anything
I think your xml format is not absolutely right.
Let you see this reference that how to bind xml data to treeview in asp.net.
http://msdn.microsoft.com/en-us/library/494y92bs%28v=vs.100%29.aspx

asp.net webform Menu control how to indent wrapped items?

I'm using a standard asp.net Menu control to display a menu on my page, and I have the text wrap option set to true. What I'd like to do is indent the wrapped text as a visual clue that its part of the line above.
I followed this question: Can you apply CSS only on text that is wrapped, i.e. the second and subsequent lines?
but I can't see how to format the MenuItem elements within the Menu control. Can this be referenced with CSS?
Not sure if this will help... but here is my html:
<asp:Menu ID="MSDSMenu" runat="server" Width="100%" CssClass="noPrint" ItemWrap="True">
<Items>
<asp:MenuItem Text="Search SDS" Value="Search MSDS" NavigateUrl="~/MSDS/SearchMSDS.aspx" />
<asp:MenuItem NavigateUrl="~/MSDS/ByDept.aspx?dept=Shipping%25%27%20OR%20UsageDept%20LIKE%20%27%25Receiving"
Text="Shipping / Receiving" Value="Shipping / Recieving" />
<asp:MenuItem NavigateUrl="~/MSDS/ByDept.aspx?dept=Other" Text="Other" Value="Other" />
</Items>
</asp:Menu>
There are several levels of styling on a menu:
<asp:Menu ID="Menu1" runat="server"
CssClass="menuBar_style" >
<LevelSubMenuStyles>
<asp:SubMenuStyle CssClass="sub_style_top" />
<asp:SubMenuStyle CssClass="sub_style_lvl1" />
</LevelSubMenuStyles>
<LevelMenuItemStyles>
<asp:MenuItemStyle CssClass="item_style_top" />
<asp:MenuItemStyle CssClass="item_style_lvl1" />
</LevelMenuItemStyles>
<Items>
<asp:MenuItem />
<asp:MenuItem />
<asp:MenuItem />
</Items>
</asp:Menu>
there's the css for the Menu itself, but then you can also define LevelSubMenuStyles and LevelMenuItemStyles, with separate style items within both of those for each level of your menu (in your case only the one level by the looks of it).
I reccommend trying to apply your wrapping to the MenuItemStyle css as this affects the actual control (i.e. the text usually), SubMenuStyle affects the container around the control I think.
Hope that makes sense... it's awfully confusing business, your best bet is to play around with the different tags for a while until you get a feel for them in your own head and hopefully you'll see what I mean.
EDIT: I've just noticed this question is from two years ago! No idea how I ended up here, one minute I was browsing the latest questions and next... I'll leave the answer here in any case as menu styling has been a source of frustration for me in the past and this may help somebody else.

dynamically add child list-view items in radio-button-list

There is this asp.net radio-button-list which have three list view items.
<asp:RadioButtonList ID="rdbFolderOptions" runat="server" RepeatDirection="Vertical"
RepeatLayout="Flow" Font-Size="Medium" AutoPostBack="true" OnSelectedIndexChanged="rdbFolderOptions_SelectedIndexChanged">
<asp:ListItem Text="Calendar" Value="0" />
<asp:ListItem Text="Tasks" Value="1" />
<asp:ListItem Text="Contacts" Value="2" />
</asp:RadioButtonList>
on click of any of the options, there should be a child list that should come that have fix options.
<asp:RadioButtonList ID="rdbSubFolder" runat="server" RepeatDirection="Vertical"
RepeatLayout="Flow" Font-Size="Medium" AutoPostBack="true" OnSelectedIndexChanged="rdbSubFolder_SelectedIndexChanged">
<asp:ListItem Text="Editor" Value="0" />
<asp:ListItem Text="Reviewer" Value="1" />
</asp:RadioButtonList>
for example :
If you have selected "calendar" than a child list should come under "calendar" indented like below.
Calendar
Editor
Reviewer
Tasks
Contacts
I am comfortable it doing with javascript/jquery/c# but not able to figure out how to ident it. Working code will be helpfull.
Update :
Check this:
How to create a treeview with radio buttons in the [grand]child nodes?
I think you are looking for TreeView Control
The TreeView Web server control is used to display hierarchical data, such as a table of contents or file directory, in a tree structure. It supports the following features:
Automatic data binding, which allows the nodes of the control to be bound to hierarchical data, such as an XML document.
Site navigation support through integration with the SiteMapDataSource control.
Node text that can be displayed as either selectable text or hyperlinks.
Customizable appearance through themes, user-defined images, and styles.
Programmatic access to the TreeView object model, which allows you to dynamically create trees, populate nodes, set properties, and so on.
Node population through client-side callbacks to the server (on supported browsers).
The ability to display a check box next to each node.

Different behavior of Sharepoint controls on postback

Some Sharepoint controls sadly behave different on postback:
I started with:
<SharePointWebControls:NoteField id="3" FieldName="MultiText" runat="server" />
<PublishingWebControls:RichLinkField id="4" FieldName="Link" runat="server" />
These controls render &nbsp for blank fields. That lead to unwanted whitespace on postback.
After some research I found a solution like
suggested here :
<PublishingWebControls:EditModePanel runat=server id="EditModePanelView" PageDisplayMode="Display" SuppressTag="true">
<SharePointWebControls:FieldValue id="3" FieldName="MultiText" runat="server"/>
<SharePointWebControls:FieldValue id="4" FieldName="Link" runat="server" />
</PublishingWebControls:EditModePanel>
<PublishingWebControls:EditModePanel runat="server" id="EditModePanelEdit">
<SharePointWebControls:NoteField id="7" FieldName="MultiText" runat="server" />
<PublishingWebControls:RichLinkField id="8" FieldName="Link" runat="server" />
</PublishingWebControls:EditModePanel>
...no &nbsp in blank fields anymore:
In Edit-Mode the specific WebControls are used.
In display mode of the page, there is used SharepointWebControls:FieldValue to simply render the content.
Now a new problem occured:
Any line breaks (rendered as br-Tags) that are entered in edit mode for a NoteField are lost, when rendered as SharePointWebControls:FieldValue. Is there any way to render the html of the NoteField as is in display mode? So that the breaks don't get lost and there are no additional non-breaking spaces?
I ended up with overwriting the Sharepoint Controls like suggested here:
I had to overwrite NoteField#RenderFieldForDisplay like this, so that NoteField behaves the same on postback and on GET:
protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
TextWriter writer = new StringWriter();
base.RenderFieldForDisplay(new HtmlTextWriter(writer));
string x= writer.ToString();
string y= " ";
string z= "<br/>";
x= x.Equals(y) ? x.Replace(y, string.Empty) : x.Replace(" ", y).Replace("\r\n", z).Replace("\n", z).Replace("\r", z);
output.Write(x);
}
This works but it sucks. I still don't get it why sharepoint controls behave different on postback and replace e.g. br-Tags with line breaks...

Categories