我正在尝试将form1.aspx中由按钮绑定的值传递给form2.aspx
form1.aspx:
<asp:Button ID="Button1" runat="server" Text="Button" CommandArgument = '<%#Eval("Parking_ID")%>' /> 该按钮位于中继器中,该中继器被绑定到Select * From [Parking]
中继器中的每个按钮都应该具有基于CommandArgument的唯一parking_Id。
在form1.aspx.vb中:
Protected Sub repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repeater1.ItemCommand
Dim value As Int32 = Convert.ToInt32(e.CommandArgument)
Response.Redirect("form2.aspx?id=" & value)
Session("field4") = value 在Form2.aspx.vb中:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim field4 As String = CType(Session.Item("field4"), String)
Parking_ID1.Text = field4但是Parking_ID1.text Label没有显示任何值。
任何帮助都将不胜感激
问候
发布于 2011-05-02 16:23:54
在设置会话之前,您正在重定向。
此外,您只需执行以下操作,就可以更轻松地获取Form2.aspx.vb中的值:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim field4 As String = Request.Querystring("id")
Parking_ID1.Text = field4您将不得不原谅我的VB.net语法,因为我使用它已经很久了,但是这个概念应该适用于您。
根据发帖者的请求扩展答案:
如果您希望传递多个参数,有几种方法可以做到这一点,尽管您的模型是实现此目的的正确基础:
Protected Sub repeater1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles repeater1.ItemCommand
Dim value As Int32 = Convert.ToInt32(e.CommandArgument)
Dim dataItem as YourStronglyTypedItem = e.Item.DataItem as YourStronglyTypedItem // c# there - sorry
Session("field4") = dataItem.Property1
Session("field5") = dataItem.Property2 // etc.
Response.Redirect("form2.aspx?Parking_ID=" & value & "&OtherProperty=" & dataItem.Property2)语法并不理想(其中一些是用c#编写的,对不起!),但从本质上讲,如果您可以(通过e.Item.DataItem)获取绑定的数据项,并将其强制转换为最初绑定的任何对象,那么您就可以从其中获取任意多的属性。
因此,假设您将数据列表绑定到它。转换为widget的e.Item.DataItem将为您提供特定Widget的值,然后您可以设置多个会话值(或者实际上只是将整个widget放入会话中),或者您可以像我上面所做的那样传递多个查询字符串参数。
希望这能帮上忙?
发布于 2011-05-02 16:29:39
您可以遵循下面的正确语法。Dim field4 As String = Request.QueryString"id“
https://stackoverflow.com/questions/5854917
复制相似问题