-2

質問するのに正しい言葉を選んだかどうかはわかりません。しかし、これが私のコードです

<asp:GridView ID="dgvJobCostList" runat="server" CellPadding="4" ForeColor="#333333" style="font-family:Verdana;font-size:10px;" AutoGenerateColumns="False" OnSelectedIndexChanged="dgvJobCostList_SelectedIndexChanged">
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                <Columns>
                    <asp:TemplateField HeaderText="Valid From">
                        <ItemTemplate>
                            <asp:Label ID="lblRateEffectiveFrom" runat="server" Text='<%# Bind("RateEffectiveFrom") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Shipper">
                        <ItemTemplate>
                            <%--<asp:Label ID="lblShipperName" runat="server" Text='<%# Bind("ShipperName") %>'></asp:Label>--%>
                            <%--<asp:Label ID="lblShipperName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Shipper.ShipperName") %>'></asp:Label>--%>
                            <asp:Label ID="lblShipperName" runat="server" Text='<%# ((BOJobInfo)Container.DataItem).oShipper.ShipperName %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Consignee">
                        <ItemTemplate>
                            <%--<asp:Label ID="lblConsigneeName" runat="server" Text='<%# Bind("ConsigneeName") %>'></asp:Label>--%>
                            <asp:Label ID="lblConsigneeName" runat="server" Text='<%# ((BOJobInfo)Container.DataItem).oConsignee.ConsigneeName %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Income">
                        <ItemTemplate>
                            <asp:Label ID="lblTotalIncome" runat="server" Text='<%# Bind("TotalIncome") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Cost">
                        <ItemTemplate>
                            <asp:Label ID="lblTotalCost" runat="server" Text='<%# Bind("TotalCost") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="CM1">
                        <ItemTemplate>
                            <asp:Label ID="lblTotalCM1" runat="server" Text='<%# Bind("TotalIncome" - "TotalCost") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

私の問題は
1です。収入と費用の差を計算し、その結果をCM1テンプレートに表示したいと思います。
2.「RateEffectiveFrom」の日付を「dd-MMM-yyyy」としてフォーマットします。これは現在「dd-MM-yyyyhh:mm:ssAM/PM」のようなものを表示しています。
以前と同じように助けてください。ありがとう :)

4

4 に答える 4

1

RowDataBoundなしで実行したい場合は、次のように実行できます。

<label id="cm1Label"><%# DataBinder.Eval(Container.DataItem, "TotalIncome") - DataBinder.Eval(Container.DataItem, "TotalCost")%></label>

または、渡された値に基づいて違いを与える小さなパブリック静的関数をサーバーに記述します

Text='<%# GetDifference(Eval("TotalIncome"),Eval("TotalCost"))%>'

日付については、次のようなことができます。

'<%# Convert.ToDateTime(Eval("RateEffectiveFrom")).ToString("dd/MM/yyyy")%>'
于 2012-05-28T07:36:17.063 に答える
0

グリッドビューのサーバー側のRowDataBoundイベントを記述します

e.Row.FindControlを使用してテンプレートコントロールを検索します。例:

protected void dgvJobCostList_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
    Label lblRateEffectiveFrom = ((Label)e.Row.FindControl("lblRateEffectiveFrom"));

    //Use following line to change the date format in RowDataBound after finding the control

    lblRateEffectiveFrom .Text = lblRateEffectiveFrom .Text.ToString(dd-MMM-yyyy")
       //do what ever you want to do here using the value of your label
  }

}

于 2012-05-28T07:19:48.317 に答える
0

This is my way,

    public decimal GetOrders(decimal order)
    {
        totalOrders += order;
        return order;
    }
    public decimal GetOrdersTotal()
    {
        return totalOrders;
    }

And,

<ItemTemplate>
 <%# GetOrders(decimal.Parse(Eval("OrderTotal").ToString())).ToString("N2")%>
</ItemTemplate>
<FooterTemplate>
<%# GetOrdersTotal().ToString("N2")%>
</FooterTemplate>

For the date, you can use same thing, or use format functions from grid property

于 2012-06-04T11:01:02.430 に答える
0

@Rahul Rに感謝します。提供されたコードサンプルはほとんど変更する必要がありませんでしたが、これらは確かに問題を解決するためのアイデアを私に与えてくれました。だから私はあなたの答えを「答え」とマークします。これが私が現在使用しているコードです

問題1の場合。

<asp:TemplateField HeaderText="Income">
    <ItemTemplate>
        <asp:Label ID="lblTotalIncome" runat="server" Text='<%# Bind("TotalIncome") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cost">
    <ItemTemplate>
        <asp:Label ID="lblTotalCost" runat="server" Text='<%# Bind("TotalCost") %>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CM1">
    <ItemTemplate>
        <asp:Label ID="lblTotalCM1" runat="server" Text='<%# Convert.ToDouble(DataBinder.Eval(Container.DataItem, "TotalIncome")) - Convert.ToDouble(DataBinder.Eval(Container.DataItem, "TotalCost"))%>'></asp:Label>
    </ItemTemplate>
</asp:TemplateField>

問題2の場合。

<asp:TemplateField HeaderText="Valid From">
                                <ItemTemplate>
                                    <asp:Label ID="lblRateEffectiveFrom" runat="server" Text='<%# Eval("RateEffectiveFrom", "{0:dd-MMM-yyyy}") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

また、アイデアを共有してくれたRanaとRizviにも感謝します。ありがとう。

于 2012-05-28T08:34:30.720 に答える