我试图在转发器中传递值,将它们绑定到按钮,并将它们从此窗体传递到另一个窗体。当我编译它时,它给我一个错误指示
System.FormatException: Input string was not in a correct format.
form1.aspx中的Repeater代码中的按钮:
<asp:Button ID="Button1" runat="server" Text="" CommandName= "TEST" CommandArgument = '<%# Eval("Parking_ID") + "," + Eval("Parking_Name") %>' />
in form1.aspx.vb Repeater_ItemCommand功能:
Protected Sub repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repeater1.ItemCommand
If (e.CommandName = "TEST") Then
Dim commandArgsAccept As String() = e.CommandArgument.ToString().Split(New Char() {","c})
Dim value As Int32 = commandArgsAccept(0).ToString
Dim value1 As String = commandArgsAccept(1).ToString
Response.Redirect("Default2.aspx?Parking_ID=" & value, True)
Response.Redirect("Default2.aspx?Parking_Name=" & value1, True)
Session("field4") = value
Session("field6") = value1
End If
End Sub
针对此问题的任何解决方案? 问候。
答案 0 :(得分:1)
<asp:Button ID="Button1" runat="server" Text="" CommandName= "TEST" CommandArgument = '<%# Eval("Parking_ID").ToString() +","+ Eval("Parking_Name").ToString() %>'/>
Protected Sub repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repeater1.ItemCommand
If (e.CommandName = "TEST") Then
Dim commandArgsAccept As String() = e.CommandArgument.ToString().Split(",")
Dim value As Int32 = commandArgsAccept(0).ToString
Dim value1 As String = commandArgsAccept(1).ToString
Session("field4") = value
Session("field6") = value1
Response.Redirect("Default2.aspx?Parking_ID=" & value & "&Parking_Name=" & value1, True)
End If
答案 1 :(得分:0)
将数据库的键字段名称放在公共变量中,这样就不会出现语法错误
public string registerKey = "myId";
protected void btnCancel_Command (object sender, CommandEventArgs e)
{
// With the CommandEventArgs you get the parameters sent
UpdatePanel2.Update ();
}
<asp: Button ID = "btnCancel" Text = "Cancel" CommandName = "CancelDeposit" OnCommand = "btnCancel_Command" runat = "server" CommandArgument = '<% # DataBinder.GetPropertyValue (Container.DataItem, registerKey)%> ">