Developer forum
E-mail notifications
How to get data for dropdownlist in datalist forms
GalleryID column in Images table is of type dropdown. Is it possible to fill the GalleryID listitems with data from Galleries table rows ?
Replies
You can but it requires 3 things.
a. That you use XSLT
b. That you use Data Lists Extended
c. The following line in the host file on your server: 127.0.0.1 yourdomainhere
Here is what to do.
1. Create a List of what you want in the dropdown (galleryname, galleryid)
2. Publish that List as an XML Publication
3. In your XSLT form template you then do like this:
<xsl:variable name="imagecategories" select="document('http://[here you type the link for your XML Publication]')/View/Rows/Row" />
Now your variable $imagecategories contains all the rows from the XML Publication and you can use them to create a selectbox.
// Sebastian
Formatted xml publication created from a datamanagment list:
<View>
<Row>
<Value Column="GalleriesID">2</Value>
<Value Column="Galleries_GalleryName">Test 2</Value>
<Value Column="Galleries_Date">Tue, 15 Dec 2009 15:21:16 GMT</Value>
</Row>
<Row>
<Value Column="GalleriesID">1</Value>
<Value Column="Galleries_GalleryName">Test 1</Value>
<Value Column="Galleries_Date">Mon, 14 Dec 2009 14:59:49 GMT</Value>
</Row>
</View>
Xslt for select:
<xsl:template match="item[Field.Systemname='Images_GalleryName']" priority="1">
<label for="Images_GalleryName">Gallery names</label>
<select>
<xsl:attribute name="name">Images_GalleryName</xsl:attribute>
<xsl:attribute name="id">Images_GalleryName</xsl:attribute>
<xsl:apply-templates select="document('http://[yourdomain]/Admin/Public/DataManagement/PublishingOutput.aspx?ID=1')/View/Row" mode="gallerynames" />
</select>
</xsl:template>
<xsl:template match="Row" mode="gallerynames">
<option>
<xsl:attribute name="value">
<xsl:value-of select="Value[@Column = 'GalleriesID']" />
</xsl:attribute>
<xsl:value-of select="Value[@Column = 'Galleries_GalleryName']" />
</option>
</xsl:template>
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8" />
<xsl:template match="/">
<View>
<xsl:for-each select="View/Rows/Row">
<xsl:copy-of select="."/>
</xsl:for-each>
</View>
</xsl:template>
</xsl:stylesheet>
Error transforming XSLT System.Xml.Xsl.XslTransformException: An error occurred while loading document 'Admin/Public/DataManagement/PublishingOutput.aspx?ID=1'. See InnerException for a complete description of the error.
Or
Error transforming XSLT System.Xml.Xsl.XslTransformException: An error occurred while loading document 'http://127.0.0.1/Admin/Public/DataManagement/PublishingOutput.aspx?ID=1'. See InnerException for a complete description of the error. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. at System.Net.HttpWebRequest.GetResponse() at
Any ideas?
I did it on different solution and it worked..
You must be logged in to post in the forum