我需要获取设置为回发到另一个页面的以下链接按钮的文本:
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("computername") %>' PostBackUrl="~/assetdetails.aspx" CommandName="Select">LinkButton</asp:LinkButton>
</ItemTemplate>我在receiving pages load事件中尝试了很多方法,但我最终得到的结果如下:
Dim GV As GridView = TryCast(PreviousPage.Master.FindControl("content").FindControl("GridView2"), GridView)
Dim LB As LinkButton = TryCast(GV.SelectedRow.Cells(0).FindControl("LinkButton1"), LinkButton)
lblAsset.Text = LB.Text显然它不起作用(返回空白,不是null),否则我不会写这篇文章。:)请帮帮忙!
发布于 2013-09-25 14:20:08
你做错了。
这里的GridView位于内容页(使用母版页)中,因此访问最初出现在内容页中的GridView如下所示:
If (Not (Me.Page.PreviousPage) Is Nothing) Then
Dim ContentPlaceHolder1 As Control =
Me.Page.PreviousPage.Master.FindControl("ContentPlaceHolder1")
Dim GV As GridView =
CType(ContentPlaceHolder1.FindControl("GridView1"), GridView)
Dim LB As LinkButton =
TryCast(GV.SelectedRow.Cells(0).FindControl("LinkButton1"), LinkButton)
lblAsset.Text = LB.Text
End If实际上,ContentPlaceHolder控件中存在GridView和其他内容。
https://stackoverflow.com/questions/18990365
复制相似问题