开发者

Accessing Details View Bind Data Before The View Is Rendered

I have a field in a details view shown below

<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>开发者_StackOverflow社区;
                <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>

Before "DTMON_F" is binded to the view I want to cut the string that is returned...Where and how might I do this?


You can implement the OnDataBinding event for each control instead of doing the bind inline. This will give you the ability to do whatever you like with the data before assigning it to the control.

Example using your Label. The same could be applied to the 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜