2011-10-06 56 views
0

在我的aspx頁面中,我有一個detailsView和一個標籤。標籤的文本應該顯示與detailsview的綁定字段相同的值。我怎樣才能讓他們兩個同時居住? 以下是我的apsx頁面,我嘗試了Eval,它沒有工作。我不想在代碼隱藏方面做到這一點。如何將boundfield值傳遞給同一頁面中的標籤?

 <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

嘗試使用DataBound事件,像這樣:

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