简体   繁体   English

如何使用javascript / jquery从aspx.cs将包含数据的列表打印到aspx

[英]how to print a list containing data into aspx from aspx.cs using javascript/Jquery

aspx.cs code aspx.cs代码

protected void Page_Load(object sender, EventArgs e)
 {

            foreach (UserDetail l in liststUser)
                            {
                                UserName = l.Name;
                                Dob = l.dob;
                                gender = l.gender;
                                ScriptManager.RegisterStartupScript(this, GetType(), "print User's bio.", " PersonBlockCreator('" + UserName + "','" + Dob + "','" + gender + "');", true);
                            }
}

.aspx code .aspx代码

<html>
    <head>
        <script type="text/Javascript">

            targetId = "#userData"; //Constant value, Do not change 
            BoxName = "box"; //Constant value, Do not change 
            j = 0;


            function PersonBlockCreator(UserName, Dob, gender) {
                $(targetId).append("<div class=" + BoxName + ">" + (j + 1) + "<div class='box-color'><h2>" + sSubjectName + "</h2><h5>"+Dob+"‏</h5><p>"+gender+" </p></div></div>");

                $(".tile").addClass(tileColor);
            }
        </script>
    </head>
    <body>
           <div class="Box" id="UserData">

                //each user data should be printed in an box
                //Example:
                //           ---------------   -----------
                //         | Nethan Walter | | Deen         |
                //         | 10-01-1990    | | 10-01-1990   |
                //         | Male          | | Male         |
                //          ---------------   --------------
           </div>

    </body>
</html>

how can i achieve this task using java Script and c# or Only by using c#. 我如何使用Java脚本和c#或仅通过使用c#来完成此任务。 Here all i want to do is : a listObject(user details) containing data in aspx.cs to be printed in aspx page on page load. 在这里,我要做的是:一个listObject(用户详细信息),其中包含aspx.cs中的数据,以在页面加载时在aspx页面中打印。 when im using above code, only first user Data is getting printed and remaining user's data is not neglected/discarded/not printing. 当使用上述代码时,仅第一个用户数据被打印,其余用户的数据不被忽略/丢弃/不打印。

You can print your table using java script. 您可以使用Java脚本打印表格。 I suggest you to pass div id into the function given below. 我建议您将div id传递给下面的函数。

function PrintSummary(tableid) { 函数PrintSummary(tableid){

var tbl = document.getElementById(tableid);
if (tbl) {

    strPrintContent += tbl.innerHTML;

    var printWin = window.open("print.html", "printSpecial");
    printWin.document.open();
    printWin.document.write(strPrintContent);
    printWin.document.close();
    printWin.print();
}

} }

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

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