2011-02-25 3 views
1

나는 세부 사항의 필드가 나는 반환되는 문자열을 잘라내려는보기로 바인더 제본있다 "DTMON_F"전에보기가 렌더링 액세스 세부 사항보기 바인딩 데이터 전에

<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> 

아래와 같이 뷰가 .. . 내가 어디에서 어떻게 할 수 있니?

답변

1

바인드 인라인 대신 각 컨트롤에 OnDataBinding 이벤트를 구현할 수 있습니다. 이렇게하면 컨트롤에 할당하기 전에 데이터로 원하는 모든 작업을 수행 할 수 있습니다.

Label을 사용하는 예입니다. 동일은 TextBox에 적용 할 수있다 : 나는이 라벨 (14)이있는 경우

<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

무엇? 어떻게 든 코드를 통합 할 수 있습니까, 아니면 각 라벨에 대해 별도의 이벤트를 만들어야합니까? –

관련 문제