2011-02-25 81 views
1

我有一個細節的視場圖所示的視圖顯示訪問詳細信息視圖綁定數據之前

<asp:BoundField DataField="DTMON_F" HeaderText="Monday Hours From: " InsertVisible="False" 
      ReadOnly="True" SortExpression="HOURS" Visible="false" /> 
     <asp:TemplateField HeaderText="Monday Hours From: " SortExpression="HOURS"> 
      <EditItemTemplate> 
       <uc1:TimePicker ID="tpMondayHours" runat="server"/> 
      </EditItemTemplate> 
     <InsertItemTemplate> 
       <%-- <uc1:TimePicker runat="server" ID="tpMondayHours" />--%> 
        <asp:TextBox ID="txtMondayHours" runat="server" Text='<%# Bind("DTMON_F") %>'></asp:TextBox> 
      </InsertItemTemplate> 
      <ItemTemplate> 
       <asp:Label ID="lblMondayHours" runat="server" Text='<%# Bind("DTMON_F") %>'></asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 

之前「DTMON_F」被綁定到我希望削減返回的字符串的觀點.. 。我在哪裏以及如何做到這一點?

回答

1

您可以爲每個控件實現OnDataBinding事件,而不是進行內聯綁定。這將使您能夠在將數據分配給控件之前對數據進行任何操作。

使用您的Label的示例。 TextBox也可以應用:

<asp:Label ID="lblMondayHours" runat="server" 
    OnDataBinding="lblMondayHours_DataBinding"></asp:Label> 

protected void lblMondayHours_DataBinding(object sender, System.EventArgs e) 
{ 
    Label lbl = (Label)(sender); 
    string yourValue = (int)(Eval("DTMON_F")); 
    // *** Do whatever you want with the value now 
    lbl.Text = yourValue; 
} 
+0

如果我有14個這些標籤要做什麼呢?我能否以某種方式整合代碼,還是必須爲每個標籤製作一個單獨的事件? – 2011-02-25 18:46:28

相關問題