如何获取父GridView的数据绑定值

发布于 2024-07-25 05:30:49 字数 508 浏览 2 评论 0原文

<asp:GridView DataSource="Reports">
    <ItemTemplate>
        <asp:TextBox Text='<%# Bind("ReportId") %>'
        <asp:Repeater DataSource="Something that is different than the GridView's DS">
            <a href='<%# Bind("ReportId", "reports.aspx?report={0}") %>'/>
        </asp:Repeater>
    </ItemTemplate>
</asp:GridView>

我知道这是无法实现的,我正在寻找一种在嵌套转发器中使用来自父 gridview 的 ReportId 的方法,有没有办法使用服务器端代码 <%# %> 来做到这一点?

<asp:GridView DataSource="Reports">
    <ItemTemplate>
        <asp:TextBox Text='<%# Bind("ReportId") %>'
        <asp:Repeater DataSource="Something that is different than the GridView's DS">
            <a href='<%# Bind("ReportId", "reports.aspx?report={0}") %>'/>
        </asp:Repeater>
    </ItemTemplate>
</asp:GridView>

I know this is inachievable, I am looking for a way to use ReportId from the parent gridview in the nested repeater, is there a way to do it with server side code <%# %>?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2024-08-01 05:30:49

设置 gridview

DataKeyField="ReportId"

并在其内部的 GridView1_ItemDataBound 事件中

protected void GridView1_ItemDataBound(object sender, GridViewItemEventArgs e)    
((TextBox)e.Item.FindControl("TextBox1")).text = GridView1.DataKeys[0].ToString();

设置文本框,并使用 ID 的值设置文本框,尝试一下,希望它有用。

Set the gridview

DataKeyField="ReportId"

and in the event GridView1_ItemDataBound inside it

protected void GridView1_ItemDataBound(object sender, GridViewItemEventArgs e)    
((TextBox)e.Item.FindControl("TextBox1")).text = GridView1.DataKeys[0].ToString();

and in this case u set the textbox with the value of the ID, try it and hope that it will be usefull.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文