Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Need help with C# xsl web page - trying to set item in drop-down list

$
0
0

I am working on an asp.net application that uses XSL heavily (unfortunately) and am trying to set Items in drop-down list controls. The controls populate as expected, but I don't know how to set the correct item (bind it to the correct entry) in the drop down control.

        <xsl:for-each select="/GenericImportMaster/MasterDefinitions">

....

            <td class="SpreadSheetEntry" style="white-space:nowrap;text-align:left;">              <select name="HostFtpSettings_{ImportMasterDefinitionId}" id="HostFtpSettings_{ImportMasterDefinitionId}" class="PropertySelect" onchange="FtpSettingsChange( this )" style="width:100px;" value="HostName">                <xsl:if test="$readonly = 'True'">                  <xsl:attribute name="disabled">true</xsl:attribute>                </xsl:if>                <option value="">None</option>                <option value="__NewFtpSettings__">(New Host Settings...)</option>                <xsl:for-each select="/GenericImportMaster/MasterDefinitions/HostFtpSettings">                  <option value="{HostName}">                    <xsl:if test="/GenericImportMaster/MasterDefinitions/HostFtpSettings/HostName = '{HostName}' ">                     <xsl:attribute name="selected">                       <xsl:value-of select="@HostName"/>                        <xsl:text>selected</xsl:text>                      </xsl:attribute>                    </xsl:if>                    <xsl:value-of select="HostName" />                 </option>                </xsl:for-each>              </select>            </td>

and the c# code is:

               thisDocument.LoadXml("<?xml version='1.0' encoding='utf-8'?><GenericImportMaster readonly='' />");                XmlNode elDocument = thisDocument.SelectSingleNode("/GenericImportMaster");                elDocument.Attributes["readonly"].InnerText = IsReadOnly.ToString();                // action attribute for new/edit mode                XmlAttribute elAction = thisDocument.CreateAttribute("action");                elDocument.Attributes.Append(elAction);                                elAction.InnerText = Request["action"];                var hosts = ImportFtpSettings.Enumerate();                // Get all the current Master Defs                var mdefs = ImportMasterDefinition.Enumerate();                bool onetime = true;                var hostMap = new List<Keys>();                                var nimd = ImportMasterDefinition.Enumerate();                foreach (var md in nimd)                {                    var innerXML = new StringBuilder(256);                    XmlElement masterDefs = thisDocument.CreateElement("MasterDefinitions");                    try                    {                        innerXML.AppendFormat(BuildInnerXML(pkField), md.ImportMasterDefinitionID);                        innerXML.AppendFormat(BuildInnerXML(fkFtpSettingsID),md.ImportFtpSettingsID);                        innerXML.AppendFormat(BuildInnerXML("Name"), md.Name);                        innerXML.AppendFormat(BuildInnerXML("DestinationTable"), md.DestinationTable);                        innerXML.AppendFormat(BuildInnerXML("DestinationSchema"), md.DestinationSchema);                        innerXML.AppendFormat(BuildInnerXML("ImportFtpSettingsID"), md.ImportFtpSettingsID);                        // populate Host FtpSettings                        if (mdefs != null && onetime)                        {                            foreach (var h in hosts)                            {                                string[] tagseq = { "HostFtpSettings""HostName" };                                innerXML.AppendFormat(BuildInnerXML(tagseq), h.Name);                                hostMap.Add(new Keys(md.ImportMasterDefinitionID,h.Name));                                //innerXML.AppendFormat("<HostFtpSettings><Name><select><option id='{0}'>{1}</option></select></Name></HostFtpSettings>",                                 //    h.ImportFtpSettingsID,h.Name);                            }                            onetime = false;                        }                        innerXML.AppendFormat(BuildInnerXML("Description"), md.Description);                        innerXML.AppendFormat(BuildInnerXML("Active"), md.Active);                    }                    catch (SystemException se)                    {                        innerXML.AppendFormat("<Status>{0}</Status>", se.Message);                    }                    masterDefs.InnerXml = innerXML.ToString();                    elDocument.AppendChild(masterDefs);                }                XmlElement elError = thisDocument.CreateElement("Error");                elError.InnerXml = errorText;                elDocument.AppendChild(elError);                xxRP.DocumentContent = thisDocument.OuterXml;                xxRP.TransformSource = "GenericImportMaster.xslt";                /*                XmlNodeList node = thisDocument.GetElementsByTagName("MasterDefinitions");                for (var i=0;i<node.Count;i++)                {                    XmlNodeList cn = node[i].ChildNodes;                    for (int ic = 0; ic < cn.Count; ic++)                    {                        if (cn[ic].Name.Contains("HostFtpSettings"))                        {                            foreach (var h in hostMap)                            {                                if (h.HostName == cn[ic].InnerText)                                {                                    XmlNode iscn = cn[ic];                                    // Get the HostName Node                                    XmlNode hn = iscn.NextSibling;                                    //XmlAttribute xa = iscn.Attributes["selected"];                                    //iscn.Value = h.HostName;                                    hn.Value = "selected";                                }                            }                        }                    }                }                */            }            catch (Exception ex)            {                LogException(ex);            }        }

The control populates as expected ( 4 entries ), but I need to set the current item to the one in the database.

Can you tell me what I am doing wrong?


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>