简体   繁体   中英

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

aspx.cs code

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

<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#. 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. 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. I suggest you to pass div id into the function given below.

function 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();
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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