繁体   English   中英

C#将表格单元数据从一页发送到另一页

[英]C# send table cell data from one page to another

我有两个页面customer.aspx和customer_detail.aspc,每个页面在文件后都有相应的代码。 目的是能够将特定表单元格的值从客户发送到customer_detail。 例如,以下javascript基于customer.aspx.cs文件中的BindTable方法将表动态呈现到customer.aspx上。 customer.aspx:

<script type="text/javascript">
        $(document).ready(function() {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "customer.aspx/BindCustomer",
                data: "{}",
                dataType: "json",
                success: function(data) {
                    for (var i = 0; i < data.d.length; i++) {
                        $("#customer_table").append("<tr><td>"+'<a id = "anchor" href="customer_individual.aspx">' + data.d[i].customer_name +'</a>'+ "</td><td>" + data.d[i].customer_id +"</td><td>" + data.d[i].total_value + "</td><td>" + data.d[i].created_date + "</td></tr>");
                    }
                },
                error: function(result) {
                alert("Error");
                }
            });
        });

上面的BindCustomer函数是一个用customer.aspx.cs编写的WebMethod,它返回绑定到customer_table的客户数组对象customer []。 注意,在上面的表的第一个td元素中,我有一个href,它将页面重定向到customer_detail.aspx。

目的是能够在单击到customer_detail.aspx.cs的链接时发送诸如customer_name的值,以便我可以使用名称查询分别存储的customer对象,并相应地填充页面。 什么是实现此目的的最佳方法? 关于如何进行的任何建议将大有帮助!

最简单的方法是使用要在查询字符串中传递的数据来格式化到customer_detail.aspx的链接,这样(它看起来与您已经在做的事情非常相似。)

<a href="/customer_detail.aspx?customerName=dataYouWantToPass">Link</a>

加载customer_detail.aspx时,您将从查询字符串中检索值。

在customer_detail.aspx中的Page_Load事件中

var customerName = Request["customerName"];

您可能更特别,说出Request.Querystring["customerName"]但在此页面上,您可能不在乎该值是在querystring还是在表单字段中传递的。 Request["customerName"]涵盖了两者。

暂无
暂无

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

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