This is a migrated thread and some comments may be shown as answers.

RadGrid with Drag/Drop using XML

5 Answers 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Farhan
Top achievements
Rank 1
Farhan asked on 05 Oct 2010, 03:14 PM
Hi,

Has anyone had any experience with or created the RadGrid drag/drop demo with XML?  I can't seem to get the GetOrders function correct which is my starting point.  Telerik doesn't seem to have a solution for this either.

I have an XML document that needs to be transformed using an xslt file before binding to the RadGrid.  I would like to use a save button that saves both the shipped and the pending order grids to two different XML documents (not new ones) that they're both initially pulling data from.  This seems like a fairly simple concept, but I've been working on this for several days and can't get past the GetOrders function that would create and assign variables for each element and attribute.  I can't even seem to create the right dataset that gets transformed.  However, I'm not opposed to using something besides a dataset.  I'm using VB, but don't mind converting the C# if anyone knows how to do this.  I'm desperate for some help fairly quickly.  I can easily create a datasource control with the xmldocument and xmlcompiledtransform, but I don't know how to create a reader that would iterate through the elements and attributes to pull the relevant nodes to assign them to variables.

Here's my xmldoc

<?xml version="1.0" encoding="utf-8"?>
<banner>
  <globals width="658" height="162" currentItem="0" radius="4" showButtons="true" buttonLocation="right" blurX="15" blurY="15" showContent="true" bgColor="#000000" bgAlpha="0.8" bgPaddingBottom="0" titleColor="#FFFFFF" titleFontSize="16" descriptionColor="#999999" descriptionFontSize="11" cssFile="css/banner.css">
    <buttonTitleColor default="#000000" rollOver="#CD0000" current="#FFFFFF" />
    <buttonDescriptionColor default="#444444" rollOver="#FF0000" current="#BBBBBB" />
  </globals>
  <item src="images/1.jpg" transition="x" timer="7">
    <buttonTitle><![CDATA[Wseat Field]]></buttonTitle>
    <buttonDescription><![CDATA[Beautiful scene of European weath field at sunset]]></buttonDescription>
    <title><![CDATA[Yellow Weath Field]]></title>
    <description><![CDATA[The Pannonian Plain is a large plain in <a href="http://www.test.com" target="_blank">Central Europe</a> that remained when the Pliocene Pannonian Sea dried out. It is a geomorphological subsystem of the Alps-Himalaya system.]]></description>
    <link>http://www.test.com<;/link>
    <target>_blank</target>
  </item>
  <item src="images/2.swf" transition="x" timer="6">
    <buttonTitle><![CDATA[Balco Lamp]]></buttonTitle>
    <buttonDescription><![CDATA[SWF Usage Example]]></buttonDescription>
    <title><![CDATA[<font color="#FFFFFF" size="36">You can use SWF</font>]]></title>
    <description><![CDATA[Sample SWF file.]]></description>
    <link>http://www.test.com/<;/link>
    <target />
  </item>
  <item src="images/3.jpg" transition="y" timer="5">
    <buttonTitle><![CDATA[Balcoon Lamp]]></buttonTitle>
    <buttonDescription><![CDATA[This Car is Sweet!]]></buttonDescription>
    <title><![CDATA[Detroit - Jan 2006]]></title>
    <description><![CDATA[This <a href="http://www.test.com" target="_blank">Infiniti Coupe</a> Concept debuted at the North American Auto Show in Detroit in Jan 2006. Rumors hint at a 325hp V-6 or an optional V-8 engine.]]></description>
    <link>http://www.test.com<;/link>
    <target>_blank</target>
  </item>
  <item src="images/4.jpg" transition="x" timer="4">
    <buttonTitle><![CDATA[farn Lamp]]></buttonTitle>
    <buttonDescription><![CDATA[Open Lamp in Evening]]></buttonDescription>
    <title><![CDATA[Open Lamp in Evening]]></title>
    <description><![CDATA[My favorite farm house nearby.]]></description>
    <link>http://www.test.com<;/link>
    <target />
  </item>
  <item src="images/5.jpg" transition="x" timer="7">
    <buttonTitle><![CDATA[Shs for Vacation]]></buttonTitle>
    <buttonDescription><![CDATA[We finally got the great shadow of blue rain drops]]></buttonDescription>
    <title><![CDATA[Car Roof Rain Drops]]></title>
    <description><![CDATA[Car Roof Rain Drops by <a href="http://www.flashcomponents.net/" target="_blank">The Great Shadow</a>. After waiting for a long time... We Finally got what we wanted, something that someone countries they wish it stops because it destroys everything and its a disaster.]]></description>
    <link>http://www.test.com<;/link>
    <target>_blank</target>
  </item>
  <item src="images/6.png" transition="alpha" timer="8">
    <buttonTitle><![CDATA[Ships for Vacation]]></buttonTitle>
    <buttonDescription><![CDATA[]]></buttonDescription>
    <title>
    </title>
    <description>
    </description>
    <link>http://www.test.com<;/link>
    <target>_blank</target>
  </item>
  <item src="images/7.jpg" transition="x" timer="4">
    <buttonTitle><![CDATA[e machine]]></buttonTitle>
    <buttonDescription><![CDATA[Historical machine]]></buttonDescription>
    <title><![CDATA[]]></title>
    <description>
    </description>
    <link>http://www.test.com<;/link>
    <target>_blank</target>
  </item>
  <item src="images/8.jpg" transition="alpha" timer="8">
    <buttonTitle><![CDATA[Red Heart & Autumn]]></buttonTitle>
    <buttonDescription><![CDATA[The Alps]]></buttonDescription>
    <title><![CDATA[European Mountains]]></title>
    <description><![CDATA[The highest mountain in the Alps is Mont Blanc, at 4,808 metres]]></description>
    <link />
    <target />
  </item>
</banner>


Here's my xslt:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
    <xsl:output method="xml" indent="yes"/>
  
    <xsl:template match="banner">
        <xsl:element name="item">
            <xsl:apply-templates/>
        </xsl:element>
    </xsl:template>
      
    <xsl:template match="item">
        <xsl:element name="item">
            <!-- place isbn attribute first -->
            <xsl:attribute name="src">
                <xsl:value-of select="@src"/>
            </xsl:attribute>
            <xsl:attribute name="transition">
                <xsl:value-of select="@transition"/>
            </xsl:attribute>
            <xsl:attribute name="timer">
                <xsl:value-of select="@timer"/>
            </xsl:attribute>
            <xsl:attribute name="dateExp">
                <xsl:value-of select="@dateExp"/>
            </xsl:attribute>
            <xsl:attribute name="dateStart">
                <xsl:value-of select="@dateStart"/>
            </xsl:attribute>
  
            <!--  convert elements to attributes -->
            <xsl:for-each select="*">
                <xsl:attribute name="{name()}">
                    <xsl:value-of select="."/>
                </xsl:attribute>
            </xsl:for-each >
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

It's the <item> node with it's attributes and elements that I'd like to use.  Please if someone knows or can help me, I'd really appreciate it.

The original GetOrders function that needs to use the above xml info:
Protected Function GetOrders() As IList(Of Order)
           Dim results As IList(Of Order) = New List(Of Order)()
           Using connection As IDbConnection = DbProviderFactories.GetFactory("System.Data.SqlClient").CreateConnection()
               connection.ConnectionString = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString
               Using command As IDbCommand = connection.CreateCommand()
                   command.CommandText = "SELECT o.OrderID, o.CustomerID, o.RequiredDate, c.CompanyName FROM orders o INNER JOIN customers c on o.customerID = c.customerID"
                   connection.Open()
                   Try
                       Dim reader As IDataReader = command.ExecuteReader()
                       While reader.Read()
                           Dim id As Integer = DirectCast(reader.GetValue(reader.GetOrdinal("OrderID")), Integer)
                           Dim customerID As String = IIf((Not reader.IsDBNull(reader.GetOrdinal("CustomerID"))), DirectCast(reader.GetValue(reader.GetOrdinal("CustomerID")), String), String.Empty)
                           Dim requiredDate As DateTime = IIf((Not reader.IsDBNull(reader.GetOrdinal("RequiredDate"))), DirectCast(reader.GetValue(reader.GetOrdinal("RequiredDate")), DateTime), DateTime.MinValue)
                           Dim companyName As String = IIf((Not reader.IsDBNull(reader.GetOrdinal("CompanyName"))), DirectCast(reader.GetValue(reader.GetOrdinal("CompanyName")), String), String.Empty)
                           results.Add(New Order(id, customerID, companyName, requiredDate))
                       End While
                   Catch ex As SqlException
                       results.Clear()
                   End Try
               End Using
           End Using
           Return results
       End Function

The other issue is that I'm using CDATA in some of the elements.  I do know that I can use the following to save the CDATA which I've done in an update/edit form, but I'm not sure how this will impact the rest of the code.  I thought I'd include it, in case it's of help:

Dim buttonTitle As RadTextBox = CType(FormView1.FindControl("buttonTitleTextBox"), RadTextBox)
DirectCast(xmlnode.SelectSingleNode("buttonTitle").FirstChild, XmlCDataSection).Value = buttonTitle.Text

Please anyone, I could really use some help with this.  Thanks.

5 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 08 Oct 2010, 03:21 PM
Hello Farhan,

What the GetOrders() method does is just take the values for the current row that is going to be moved, so you can disregard what actions are performed there as long as you make it return an IList<Order> object with the needed data.

Please, review the following MSDN articles in order to implement a way to handle your XML data:
XmlTextReader Class
XML and the DataSet

All the best,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Farhan
Top achievements
Rank 1
answered on 11 Oct 2010, 06:59 AM
Thanks Tsvetina,

I've seen those links before, but I'll take a closer look at them.  However, I can't help but wonder where the RadGrids pull the data from if not from the GetOrders functions?  I thought the NeedDataSource indirectly pulls the data created from that function?  I can't seem to get the RadGrids to show the data without setting a datasource for each of the RadGrids, since I don't know whre they're getting the dat to begin with.  Can you tell me what sub, datasource, or function pulls the data?

Thanks,
Farhan
0
Tsvetina
Telerik team
answered on 13 Oct 2010, 08:04 AM
Hi Farhan,

Please, excuse me for misleading you, you are correct, the GetOrders() method creates the datasources for both RadGrids.

Still, what you should have in mind when creating the equivalent method is that you need to parse sets of values (in this case) id, customerID, companyName, requiredDate and on each set passed you need to create and object holding it together and add it in a container collection which when the parsing is over has to be returned by the method.

As the source used is XML there will be almost no similarities in code, so you may ignore it, only the returned result should be the same.

All the best,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Farhan
Top achievements
Rank 1
answered on 18 Oct 2010, 04:25 PM
Hi Tsvetina,

So, I think I finally have it.  Thought I'd share in case this is of help to anyone else out there or Telerik decides they want to create a demo for and XML drag and drop grid as well:

Keep in mind, I'm using my own variables, so people will have to use their own.

The GetOrders() function can be changed to:

        Protected Function GetOrders(ByVal src As String, ByVal transition As String, ByVal timer As String, ByVal OrderId As Integer, ByVal buttonTitle As String) As IList(Of Order)
            Const LinksDirectory As String = "~/scripts/"
            Dim LinksFile As String = "banner.xml"
            Dim LinksPath As String
  
            LinksPath = String.Concat(LinksDirectory, LinksFile)
            Dim xDocument1 As XDocument = XDocument.Load(Server.MapPath(LinksPath))
            Dim results As IList(Of Order) = New List(Of Order)()
                results = (From item In xDocument1.Descendants("item") Select New Order(item.Attribute("src").Value, item.Attribute("transition").Value, item.Attribute("timer").Value, item.Element("OrderId").Value, item.Element("buttonTitle").Value)).ToList()
  
            For i As Integer = 0 To results.Count - 1
                Console.WriteLine("{0} - {1} - {2} - {3} - {4}", results(i).src, results(i).transition, results(i).timer, results(i).OrderId, results(i).buttontitle)
              Next
            Return results
  
        End Function

You'll notice that attributes and elements can be used.  This uses the element "item" as an element anywhere in the XML file as a descendant and all of the nodes that are a part of it.

The second part that should be changed is the following from the "PendingOrdersStore() as Ilist(of Order)"
from:

obj = GetOrders()

to:

obj = GetOrders(src, transition, timer, OrderId, buttonTitle)

the final part of this is changing the class to:

    Protected Class Order
        Private m_Src As String
        Private m_Transition As String
        Private m_Timer As String
        Private m_OrderId As Integer
        Private m_ButtonTitle As String
        Public Sub New(ByVal src As String, ByVal transition As String, ByVal timer As String, ByVal OrderId As Integer, ByVal buttonTitle As String)
            m_Src = src
            m_Transition = transition
            m_Timer = timer
            m_OrderId = OrderId
            m_ButtonTitle = buttonTitle
        End Sub
        Public ReadOnly Property src() As String
            Get
                Return m_Src
            End Get
        End Property
        Public ReadOnly Property transition() As String
            Get
                Return m_Transition
            End Get
        End Property
        Public ReadOnly Property timer() As String
            Get
                Return m_Timer
            End Get
        End Property
        Public ReadOnly Property OrderId() As Integer
            Get
                Return m_OrderId
            End Get
        End Property
        Public ReadOnly Property buttontitle() As String
            Get
                Return m_ButtonTitle
            End Get
        End Property
    End Class
End Class

As soon as I complete this, I'll try to post a sample project for anyone that might be interested.  I'm not entirely sure this is the most efficient way, but it works so far for me.  I have to create a save function for the XML file in the RowDrop.  Otherwise it doesn't do anything.  However, I'm not entirely sure this will save the file, yet...as I haven't tested it, yet.

Any thoughts?
0
Tsvetina
Telerik team
answered on 21 Oct 2010, 12:37 PM
Hello Farhan,

Our system indicates that you have also opened a formal support ticket concerning the same matter, so in order to avoid duplicate posts, I am closing this forum thread. Still, you can feel free to reopen it in order to share your findings with the community if you would like to.

Greetings,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Farhan
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Farhan
Top achievements
Rank 1
Share this question
or