如何在asp.net中使用QueryString传递和检索表行数据

时间:2016-09-22 12:33:35

标签: c# asp.net datatables

我有一个DataTable

我创建了这个

var a=[];
$("#DataTable tbody").on( 'click', 'tr', function () 
{       
    a=table.row( this ).data();
});

现在我想使用按钮单击

上的查询字符串将此数组a []传递给另一个Web表单
<asp:Button ID="button" onclick="click_function"/>

然后

[WebMethod]
click_function()
          {
          var darr = [];
          darr = table.row('.selected').data();

          var url = "QuestionDetail.htm?QuestionId=" + darr;
          window.location.href = url;
          }

我该怎么办?

而且我必须在新的webform中检索这个数组。那么,我将获得该行的数据

2 个答案:

答案 0 :(得分:1)

我猜那个

// JavaScript    
var table = $("#DataTable").DataTable();

如果是这种情况,那么我会在表单上添加一个隐藏字段

<!-- HTML -->
<input type="hidden" runat="server" id="hfSelectedRow" />

并将数据设置为该字段

// JavaScript
$("#DataTable tbody").on( 'click', 'tr', function () 
{       
    $('#hfSelectedRow').val(table.row( this ).data());
});

所以现在在服务器上你可以通过

来检索数据
[WebMethod]
protected void button_click() 
{
    Response.Redirect("QuestionDetail.htm?QuestionId=" + hfSelectedRow.Value);
}

答案 1 :(得分:0)

public partial class Employeedetail : System.Web.UI.Page {
    // SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ToString());
    protected void Page_Load(object sender, EventArgs e) {
        string strEid = Request.QueryString["EId"];
        DisplayEmployeeDetail(strEid);
    }

    public DataTable DisplayEmployeeDetail(string strEid) {           
        DAL.EMPDA db = new DAL.EMPDA();
        EMPBOL objEMPBOL = new EMPBOL();
        objEMPBOL.e_id = strEid;
        DataTable dt = db.EmpDetail(objEMPBOL);

        Txtcode.Text = dt.Rows[0]["emp_Code"].ToString();
        TxtFName.Text = dt.Rows[0]["emp_firstname"].ToString();
        TxtLName.Text = dt.Rows[0]["emp_lastname"].ToString();
        TxtDesig.Text = dt.Rows[0]["emp_designation"].ToString();
        Txtbirthdate.Text = dt.Rows[0]["emp_dob"].ToString();
        TxtQualification.Text = dt.Rows[0]["emp_qualification"].ToString();
        Txtempcity.Text = dt.Rows[0]["emp_city"].ToString();
        Txtemailid.Text = dt.Rows[0]["emp_email"].ToString();
        Txtphonenumber.Text = dt.Rows[0]["emp_phone"].ToString();
        Txtsalry.Text = dt.Rows[0]["emp_salary"].ToString();
        return dt;           
    }
}
相关问题