1

我正在尝试拆分 gridview 的超链接列中存在的值。我无法得到我需要的东西。

这是我的代码

            <asp:TemplateField HeaderText="Budgeted Profit" SortExpression="Budgeted Profit" HeaderStyle-CssClass="StrongText"  HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="Medium" 
                                  HeaderStyle-ForeColor="Blue" HeaderStyle-Font-Underline="true"  ItemStyle-Width="3%" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Bottom" HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="Bottom">
                        <ItemTemplate>
                              <asp:HyperLink runat="server" ID="HyperLink7" NavigateUrl='<%#"PM_Prof_budgetedGraph.aspx?ProjectID="+ Eval("Project ID")%>' Text='<%#Eval("Budgeted Profit").ToString().Split(new string[]{";"},StringSplitOptions.None)[0]%>' ForeColor="BLUE" Target="_blank"></asp:HyperLink>
                              <asp:Label ID="lblProfit" runat="server"></asp:Label>
                        </ItemTemplate>
            </asp:TemplateField>

我试过这个:

  Text=<%# Eval("Budgeted Profit").ToString().Split('-')[0] %> />

你能帮我解决这个问题吗

4

1 回答 1

0

在您的代码中创建受保护的函数,如下所示:

    protected string GetProfitText(object o)
    {
        string budget = o.ToString();
        return budget.Split('-')[0];

    }

并在 aspx 文件中:

<asp:TemplateField HeaderText="Budgeted Profit" SortExpression="Budgeted Profit" 
                    HeaderStyle-CssClass="StrongText"  HeaderStyle-Font-Bold="true" HeaderStyle-Font-Size="Medium" 
                    HeaderStyle-ForeColor="Blue" HeaderStyle-Font-Underline="true"  ItemStyle-Width="3%" ItemStyle-HorizontalAlign="Left" ItemStyle-VerticalAlign="Bottom" HeaderStyle-HorizontalAlign="Left" HeaderStyle-VerticalAlign="Bottom">
    <ItemTemplate>
        <asp:HyperLink runat="server" ID="HyperLink7" 
                        NavigateUrl='<%#"PM_Prof_budgetedGraph.aspx?ProjectID="+ Eval("Project ID")%>' 
                        Text='<%# GetProfitText(DataBinder.Eval(Container.DataItem,"Budgeted Profit")) %>' 
                        ForeColor="BLUE" Target="_blank"></asp:HyperLink>
        <asp:Label ID="lblProfit" runat="server"></asp:Label>
    </ItemTemplate>
</asp:TemplateField>
于 2012-12-20T04:54:49.027 回答