我如何格式化数据绑定文本框中的文本? [英] How can I format the text in a databound TextBox?

查看:121
本文介绍了我如何格式化数据绑定文本框中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的ListView具有以下EditItemTemplate模板:

I have ListView that has the following EditItemTemplate:

<EditItemTemplate>
    <tr style="">
        <td>
            <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
            <asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
        </td>
        <td>
            <asp:TextBox ID="FundingSource1TextBox" runat="server" Text='<%# Bind("FundingSource1") %>' />
        </td>
        <td>
            <asp:TextBox ID="CashTextBox" runat="server" Text='<%# Bind("Cash") %>' />
        </td>
        <td>
            <asp:TextBox ID="InKindTextBox" runat="server" Text='<%# Bind("InKind") %>' />
        </td>
        <td>
            <asp:TextBox ID="StatusTextBox" runat="server" Text='<%# Bind("Status") %>' />
        </td>
        <td>
            <asp:TextBox ID="ExpectedAwardDateTextBox" runat="server" Text='<%# Bind("ExpectedAwardDate","{0:MM/dd/yyyy}) %>' onclientclick="datepicker()" />
        </td>
    </tr>
</EditItemTemplate>

我想格式化 ExpectedAwardDateTextBox 所以它显示了一个短日期时间,但还没有找到一个办法做到这一点无需进入code后面。在项目模板,我有以下行来格式化出现在吊牌日期:

I would like to format the ExpectedAwardDateTextBox so it shows a short date time but haven't found a way to do this without going into the code behind. In the Item template I have the following line to format the date that appears in the lable:

<asp:Label ID="ExpectedAwardDateLabel" runat="server" Text='<%# String.Format("{0:M/d/yyyy}",Eval("ExpectedAwardDate")) %>' />

和我想找到一个类似的方法做的 InsertTemplate则

And I would like to find a similar method to do with the insertItemTemplate.

推荐答案

您可以使用绑定()超载是这样的:

You can use the Bind() overload like this:

<%# Bind("ExpectedAwardDate", "{0:M/d/yyyy}") %>

同样为您评估和演示过:

Same for your Eval too:

<asp:Label ID="ExpectedAwardDateLabel" runat="server" 
           Text='<%# Eval("ExpectedAwardDate","{0:M/d/yyyy}") %>' />

这篇关于我如何格式化数据绑定文本框中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆