2011-12-12 138 views
0

在默认页面上使用GridView并希望显示在另一个页面上选择的行的详细信息。用于捕捉和发送datakey的代码 -在页面之间传递数据键

protected void SelectedIndexChanged(object sender, EventArgs e) 
{ 
      int index = GridView1.SelectedIndex; 
      Response.Redirect("InvoicePage.aspx? EntityID= " + GridView1.DataKeys[index].Value.ToString()); 
} 

而且用于检索值的代码是 -

protected void Page_Load(object sender, EventArgs e) 
{ 
    string id = Request.QueryString["EntityID"]; 
} 

我的问题是id变量是接收页面上的空。我错过了什么?

回答

1

你的URL看起来应该是这样的:InvoicePage.aspx?EntityID=",没有足够的空间之前或之后EntityID

0

顺便说一句删除空格:aspx? <> * ENTITYID <> * =

protected void SelectedIndexChanged(object sender, EventArgs e) 
{ 
      int index = GridView1.SelectedIndex; 
      string id = GridView1.DataKeys[index].Value.ToString(); 
      Response.Redirect("InvoicePage.aspx?EntityID="+id); 
} 

尝试添加:

private string _EntityId; 

    //To check if value pass on query string 
    //but this is not really required if you want 
    public string EntityId 
      { 
       get 
       { 
        if (Request.QueryString["EntityID"] != null) 
        { 
         try 
         { 
          _EntityId = Convert.ToString(Request.QueryString["EntityID"].ToString()); 

         } 
         catch (Exception ex) 
         { 

          throw new Exception(ex.Message); 
         } 
        } 
        else 
        { 
         _EntityId="0"; 
        } 

        return _EntityId; 
       } 
      } 


protected void Page_Load(object sender, EventArgs e) 
{ 
    //Request.QueryString["EntityID"].ToString(); 
    string id = EntityId; 
} 

Regads