根据数据库值检查下拉列表

checking the dropdownchecklist based on database values

本文关键字:检查 下拉列表 数据库      更新时间:2023-09-26

我想根据数据库值检查下拉列表

我的脚本

  <script>
    function myfunction(para) {
        $(document).ready(function (para) {
            $('#ContentPlaceHolder1_s10').val(para);
            $('#ContentPlaceHolder1_s10').dropdownchecklist('refresh');
            $('#ContentPlaceHolder1_s10').dropdownchecklist();
        });
    }
</script>

我的 C# 页

 int[] para;
    para = new int[] { 1,2,3 };
    pl.qid = questionID;
    Profile.questionid.questionID = questionID;
    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp", "<script     type='text/javascript'>myFunction("+para+");</script>", false);

厌倦了搜索结果,一些身体可以指导我如何

检查

下拉列表检查基于数据库值

提前致谢

我使用此下拉列表检查

http://dropdown-check-list.googlecode.com/svn/trunk/doc/dropdownchecklist.html

你正在将一个 Javascript 字符串输出到 RegisterStartupScript 中的页面,所以你需要将para格式化为其值的正确字符串表示形式。目前,它可能只是输出类似 myFunction(System.Array) .

因此,您需要一个字符串,表示para中值的逗号分隔列表。String.Join()方法将允许您执行以下操作:

int[] para;
para = new int[] { 1,2,3 };
pl.qid = questionID;
Profile.questionid.questionID = questionID;
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "tmp",
    "<script type='text/javascript'>myFunction([" + string.join(",", para) + "]);</script>", false);

这应该正确输出myFunction([1,2,3]);

作为一般规则,如果您不确定为什么某些服务器生成的 javascript 或 html 没有行为,请始终先执行视图源代码以查看实际输出的内容以及需要调查的内容。