如何将boundfield值传递给同一页面中的标签?

时间:2011-10-06 19:59:07

标签: asp.net eval detailsview

在我的aspx页面中,我有一个detailsView和一个标签。标签的文本应显示与detailsview的boundfield相同的值。如何让他们同时填充? 以下是我的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>

1 个答案:

答案 0 :(得分:1)

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

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