2014-03-06 50 views
0

我需要分配int值隱藏filed.But失敗指定int值隱藏字段

這裏去我的代碼

ASP.NET

<asp:HiddenField ID="hdnCId" runat="server" /> 

C#

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!IsPostBack) 
    { 
     int Id= 0; 
     if (Request.QueryString["Id"] != "" && Request.QueryString["Id"] != null) 
     { 
      ChurchId = Convert.ToInt32(Request.QueryString["Id"]); 
     } 
     else 
     { 
      Id = -1; 
     } 

     hdnCId.Value =Id; 
    } 
} 

回答

3

隱藏字段只需要字符串

if (Request.QueryString["Id"] != "" && Request.QueryString["Id"] != null) 
     { 
      hdnCId.Value = Request.QueryString["Id"].ToString(); 
     } 

只是用它

//when there is some value in it 

Int32 Id = Convert.ToInt32(hdnCId.Value); 
2

隱藏字段店值的字符串時,這會做

轉換爲int值。 將代碼更改爲

hdnCId.Value =Id.ToString();