【问题标题】:How to pass the boundfield value to a label in the same page?如何将boundfield值传递给同一页面中的标签?
【发布时间】:2011-12-02 13:08:31
【问题描述】:

在我的 aspx 页面中,我有一个 detailsView 和一个标签。标签的文本应显示与详细信息视图的绑定字段相同的值。如何同时填充它们? 以下是我的 apsx 页面,我尝试了 Eval,但没有成功。我不想在代码隐藏中这样做。

        <tr>
    <td > <asp:label runat="server" text='<%# Eval("ReporterName")%>'/></td>
        </tr>

<tr>
<td>
<asp:DetailsView ID="DetailsView1" runat="server" >

    <Fields>
        <asp:BoundField DataField="sprID" HeaderText="SPRID" ReadOnly="True" 
            SortExpression="sprID" >
        <HeaderStyle Width="230px" />
        </asp:BoundField>
        <asp:BoundField DataField="ProductName" HeaderText="Product" 
            SortExpression="ProductName" />
        <asp:BoundField DataField="DivisionName" HeaderText="Technology Group" 
            SortExpression="DivisionName" />
        <asp:BoundField DataField="DisciplineName" HeaderText="Discipline" 
            SortExpression="DisciplineName" />
        <asp:BoundField DataField="ReporterName" HeaderText="Reporter" 
            SortExpression="ReporterName" />
        <asp:BoundField DataField="OwnerName" HeaderText="Owner" 
            SortExpression="OwnerName" />
        <asp:BoundField DataField="SalesLeadName" HeaderText="SalesLead" 
            SortExpression="SalesLeadName" />
        <asp:BoundField DataField="RegionName" HeaderText="Region" 
            SortExpression="RegionName" />

    </Fields>

【问题讨论】:

    标签: asp.net eval detailsview


    【解决方案1】:

    尝试使用DataBound 事件,如下所示:

    protected void DetailsView1_DataBound(object sender, EventArgs e)
    {
        Label1.Text = DataBinder.Eval(DetailsView1.DataItem, "SomeValue").ToString();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 2015-12-08
      • 2017-08-26
      相关资源
      最近更新 更多