• <bdo id='KRliF'></bdo><ul id='KRliF'></ul>
    <tfoot id='KRliF'></tfoot>
        <i id='KRliF'><tr id='KRliF'><dt id='KRliF'><q id='KRliF'><span id='KRliF'><b id='KRliF'><form id='KRliF'><ins id='KRliF'></ins><ul id='KRliF'></ul><sub id='KRliF'></sub></form><legend id='KRliF'></legend><bdo id='KRliF'><pre id='KRliF'><center id='KRliF'></center></pre></bdo></b><th id='KRliF'></th></span></q></dt></tr></i><div id='KRliF'><tfoot id='KRliF'></tfoot><dl id='KRliF'><fieldset id='KRliF'></fieldset></dl></div>

      1. <small id='KRliF'></small><noframes id='KRliF'>

      2. <legend id='KRliF'><style id='KRliF'><dir id='KRliF'><q id='KRliF'></q></dir></style></legend>

        格式化 DataBinder.Eval 数据

        时间:2023-05-21

          • <i id='8vK1g'><tr id='8vK1g'><dt id='8vK1g'><q id='8vK1g'><span id='8vK1g'><b id='8vK1g'><form id='8vK1g'><ins id='8vK1g'></ins><ul id='8vK1g'></ul><sub id='8vK1g'></sub></form><legend id='8vK1g'></legend><bdo id='8vK1g'><pre id='8vK1g'><center id='8vK1g'></center></pre></bdo></b><th id='8vK1g'></th></span></q></dt></tr></i><div id='8vK1g'><tfoot id='8vK1g'></tfoot><dl id='8vK1g'><fieldset id='8vK1g'></fieldset></dl></div>

              <bdo id='8vK1g'></bdo><ul id='8vK1g'></ul>

              • <small id='8vK1g'></small><noframes id='8vK1g'>

                  <tbody id='8vK1g'></tbody>
                <legend id='8vK1g'><style id='8vK1g'><dir id='8vK1g'><q id='8vK1g'></q></dir></style></legend>

                1. <tfoot id='8vK1g'></tfoot>
                  本文介绍了格式化 DataBinder.Eval 数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  如何格式化来自 ASPX 页面中 DataBinder.Eval 语句的数据?

                  How can I format data coming from a DataBinder.Eval statement in an ASPX page?

                  例如,我想在主页中以特定格式显示新闻项目的发布日期.我正在使用 ASP.NET 2.0 Repeater 控件来显示新闻项目列表.

                  For example, I want to display the published date of the news items in a particular format in the homepage. I'm using the ASP.NET 2.0 Repeater control to show the list of news items.

                  代码如下:

                  <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1">
                  <HeaderTemplate><table cellpadding="0" cellspacing="0" width="255"></HeaderTemplate>
                  <ItemTemplate>
                      <tr><td >
                              <a href='/content/latestNews.aspx?id=<%#DataBinder.Eval(Container.DataItem, "id") %>'>
                                  <asp:Label ID="lblNewsTitle" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "title") %>'></asp:Label>
                              </a>
                      </td></tr>
                      <tr><td>
                             <asp:Label ID="lblNewsDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "publishedDate"))%>'></asp:Label>
                      </td></tr>
                  </ItemTemplate>
                  <FooterTemplate></table></FooterTemplate></asp:Repeater>
                  

                  有没有一种方法可以调用自定义方法,并将 DataBinder.Eval 值作为其参数(如下所示)?

                  Is there a way I could call a custom method with the DataBinder.Eval value as its parameter (something like below)?

                  <asp:Label ID="lblNewsDate" runat="server" Text='<%# GetDateInHomepageFormat(DataBinder.Eval(Container.DataItem, "publishedDate")) )%>'></asp:Label>
                  

                  如果是,那么我在哪里编写 GetDateInHomepageFormat 方法?我在页面后面的代码中进行了尝试,但出现了运行时错误?如果这不可能,有没有办法进行内联格式化?

                  If yes, then where do I write the GetDateInHomepageFormat method? I tried out in the code behind page but got a run time error? If this is not possible, is there a way to do inline formatting?

                  推荐答案

                  DataBinder.Eval 有一个可选的重载来提供格式:

                  There is an optional overload for DataBinder.Eval to supply formatting:

                  <%# DataBinder.Eval(Container.DataItem, "expression"[, "format"]) %>
                  

                  格式参数是一个字符串值,使用值占位符替换语法(称为复合格式)如下:

                  The format parameter is a String value, using the value placeholder replacement syntax (called composite formatting) like this:

                  <asp:Label id="lblNewsDate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "publishedDate", "{0:dddd d MMMM}") %>'</label>
                  

                  这篇关于格式化 DataBinder.Eval 数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用c#将格式从一行复制到另一行 下一篇:如何使用缩写的时区显示 DateTime?

                  相关文章

                  <tfoot id='FCy99'></tfoot>

                  <small id='FCy99'></small><noframes id='FCy99'>

                    <legend id='FCy99'><style id='FCy99'><dir id='FCy99'><q id='FCy99'></q></dir></style></legend>
                  1. <i id='FCy99'><tr id='FCy99'><dt id='FCy99'><q id='FCy99'><span id='FCy99'><b id='FCy99'><form id='FCy99'><ins id='FCy99'></ins><ul id='FCy99'></ul><sub id='FCy99'></sub></form><legend id='FCy99'></legend><bdo id='FCy99'><pre id='FCy99'><center id='FCy99'></center></pre></bdo></b><th id='FCy99'></th></span></q></dt></tr></i><div id='FCy99'><tfoot id='FCy99'></tfoot><dl id='FCy99'><fieldset id='FCy99'></fieldset></dl></div>

                        <bdo id='FCy99'></bdo><ul id='FCy99'></ul>