首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PreviousPage Findcontrol问题

PreviousPage Findcontrol问题
EN

Stack Overflow用户
提问于 2013-09-25 03:28:42
回答 1查看 779关注 0票数 2

我需要获取设置为回发到另一个页面的以下链接按钮的文本:

代码语言:javascript
复制
<ItemTemplate>
     <asp:LinkButton ID="LinkButton1" runat="server" Text='<%# Bind("computername") %>' PostBackUrl="~/assetdetails.aspx" CommandName="Select">LinkButton</asp:LinkButton>
</ItemTemplate>

我在receiving pages load事件中尝试了很多方法,但我最终得到的结果如下:

代码语言:javascript
复制
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),否则我不会写这篇文章。:)请帮帮忙!

EN

回答 1

Stack Overflow用户

发布于 2013-09-25 14:20:08

你做错了。

这里的GridView位于内容页(使用母版页)中,因此访问最初出现在内容页中的GridView如下所示:

代码语言:javascript
复制
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和其他内容。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18990365

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档