0
有沒有辦法將文本從列表視圖控制器傳遞到OnClick子例程?例如,列表視圖中有一個標籤,我在列表視圖中附加了一個按鈕,並在其上附加了一個OnClick子例程。現在我想將標籤中的文本傳遞給OnClick子例程。我希望這是有道理的。樓下是我的代碼:將文本從列表視圖控制器傳遞到OnClick Sub VB.Net
VB.Net代碼:
Protected Sub AmButtonClick(ByVal sender As Object, ByVal e As System.EventArgs)
Dim url As String = CType(Me.AmListViewDetails.FindControl("merchantLink"), Label).Text
Dim sb As New StringBuilder()
sb.Append("<script type = 'text/javascript'>"_
sb.Append("window.open('")
sb.Append(url)
sb.Append("');")
sb.Append("</script>")
ClientScript.RegisterStartupScript(Me.GetType(), "script", sb.ToString())
End Sub
ASP.Net:
<asp:ListView runtat="server" ID="AmListViewDetails" ...>
<ItemTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<asp:Label ID="merchantLink" runat="server" Text='<%Eval("Link")%>' />
</td>
</tr>
<tr runat="server">
<td runat="server">
<asp:Button ID="AmBtn" runat="server" Text="Checkout" OnClick="AmButtonClick"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:ListView>
檢索'Link'字段的值,最好的辦法是到該字段添加到ListView的'DataKeyNames'財產。該方法在這裏解釋:http://stackoverflow.com/questions/36813634/how-to-retrieve-the-value-of-a-listview-item-in-the-same-row-as-a-linkbutton/ 36814031#36814031。 – ConnorsFan