asp.net页面上调用后台代码的问题?

来源:百度知道 编辑:UC知道 时间:2024/06/02 15:13:51
<asp:Label ID="Label10" runat="server" Text='<%# DisCount() %>'></asp:Label>
DisCount()是我写在后台的,代码如下:
protected string DisCount()
{
string money = null;
GameCardModels.Card card = (GameCardModels.Card)CardManager.GetAllCards();
RoleInfo role = UserRoleManager.GetUserRoleById(2);
money = (Convert.ToInt32(card.CardPrice) * role.DisCount / 100).ToString();
return money;
}
在页面调用会该页无法显示,请高手帮我解决下,有加分。

这是我以前用过的,你看看,对你或许有启发。
<asp:Label ID="Label4" Width="440px" runat="server" Text='<%# getString((string)DataBinder.Eval(Container.DataItem,"context"),250) %>'></asp:Label>
protected string getString(string StringInput, int StringLength)
{
if (StringInput == "" || StringInput == null)
{ return ""; }
string tempTitle = "";
StringInput = StringInput.TrimEnd(null);
if (StringInput.Length > StringLength)
{ tempTitle = StringInput.Substring(0, StringLength - 3) + "..."; }
else
{ tempTitle = StringInput; }
return tempTitle;
}

protected string DisCount() 改为 public string DisCount() 试试

在DisCount()这个方法处插个断点看看返回的money有没有值,我看你前台调用没问题的

如果money有值,把protected 改为public