简体   繁体   English

XSL复选框显示检查数据库中的值是否为1

[英]XSL checkbox display checked if value is 1 from database

How do I read a checkbox value in xsl? 如何读取xsl中的复选框值? I have a value that I read from database and based on this value this checkbox will either be check or unchecked. 我有一个从数据库读取的值,基于此值,此复选框将处于选中状态或未选中状态。 I have this snipplet but the checkbox does not check even when the database_column value is 1. 我有此代码段,但是即使database_column值为1,复选框也不会检查。

<xsl:template.....>
     <form....>
        <input type="checkbox" id="functional_test" name="DATABASE_COLUMN">
           <xsl:if test="//DATABASE_COLUMN='1'">
                <xsl:attribute name="checked">checked</xsl:attribute> 
           </xsl:if>

       </input>
     </form>
</xsl:template>

EDIT: I also have problems retrieving the textarea values. 编辑:我也有检索textarea值的问题。 This textarea value is actually from a select option. 该textarea值实际上来自选择选项。 But when this value is retrieved it's from a database, I have no idea why the value is not appearing. 但是,当从数据库中检索到此值时,我不知道为什么未显示该值。 My code looks like this: 我的代码如下所示:

 <label class="control-label Mandatory" for="txtRecommendedAction"> Recommended Action*
    <button type="button" class="btn btn-default" href="#modalRecommended" data-toggle="modal"> Retrieve  </button>
 </label>
  <textarea class="form-control" id="txtRecommendedAction" name="recommended_action" rows="6" value="{//RECOMMENDED_ACTION}"/>


It just does not show the correct value in the textarea. 它只是在文本区域中没有显示正确的值。 Any idea what am I missing? 知道我想念什么吗?

I know it's weird to answer my own question but after researching the following code did help: 我知道回答我自己的问题很奇怪,但是在研究以下代码后确实有所帮助:

<xsl:element name="input">
          <xsl:attribute name="type">radio</xsl:attribute> <!-- or checkbox -->
          <xsl:attribute name="name">needModeration</xsl:attribute>
          <xsl:attribute name="value">true</xsl:attribute>
          <xsl:if test="contains(needModeration,'true')"> <!-- just change this variable-->
              <xsl:attribute name="checked">
              </xsl:attribute>
          </xsl:if>
</xsl:element>

And in my html, it did check or uncheck based on the values. 在我的html中,它确实根据值检查或取消检查。 :D :D

I got the answer from this forum: http://forums.asp.net/t/1036574.aspx 我从这个论坛获得了答案: http : //forums.asp.net/t/1036574.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM